From 90b52ca4265bb0faa6783257ec215991ca355945 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Thu, 14 May 2015 16:28:24 -0500
Subject: [PATCH] oops: Fix saving of custom data for new entries

---
 include/class.dynamic_forms.php | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php
index 43ae645c7..d062222b1 100644
--- a/include/class.dynamic_forms.php
+++ b/include/class.dynamic_forms.php
@@ -1214,6 +1214,7 @@ class DynamicFormEntry extends VerySimpleModel {
         if (count($this->dirty))
             $this->set('updated', new SqlFunction('NOW'));
 
+        $wasnew = $this->__new__;
         if (!parent::save($refetch || count($this->dirty)))
             return false;
 
@@ -1228,9 +1229,15 @@ class DynamicFormEntry extends VerySimpleModel {
             ) {
                 continue;
             }
-            // Set the entry ID here so that $field->getClean() can use the
+            // Set the entry here so that $field->getClean() can use the
             // entry-id if necessary
             $a->entry = $this;
+
+            // If this is a new entry, then ensure that the field is
+            // connected to the data associated with this entry
+            if ($wasnew)
+                $field->setForm($this);
+
             try {
                 $val = $field->to_database($field->getClean());
             }
-- 
GitLab