From e5d61922d2d89c65993ad276f886452a3e81a6d1 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Tue, 7 Oct 2014 08:48:39 -0500
Subject: [PATCH] forms: If an answer has no saved value, use the field

When processing the value of a DynamicFormEntryAnswer, if there is no
database-backed, value, then use the value of the associated field.
---
 include/class.dynamic_forms.php | 10 ++++++----
 include/class.ticket.php        |  1 +
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php
index 59605162d..174c93153 100644
--- a/include/class.dynamic_forms.php
+++ b/include/class.dynamic_forms.php
@@ -1008,10 +1008,12 @@ class DynamicFormEntryAnswer extends VerySimpleModel {
     }
 
     function getValue() {
-        if (!$this->_value && isset($this->value))
-            $this->_value = $this->getField()->to_php(
-                $this->get('value'), $this->get('value_id'));
-        return $this->_value;
+        $value = $this->getField()->to_php(
+            $this->get('value'), $this->get('value_id'));
+        if (!$value && $this->getEntry()->getSource()) {
+            return $this->getEntry()->getField(
+                $this->getField()->get('name'))->getClean();
+        }
     }
 
     function getIdValue() {
diff --git a/include/class.ticket.php b/include/class.ticket.php
index 0dd075952..c4b6d3e94 100644
--- a/include/class.ticket.php
+++ b/include/class.ticket.php
@@ -2367,6 +2367,7 @@ class Ticket {
 
         // Create and verify the dynamic form entry for the new ticket
         $form = TicketForm::getNewInstance();
+        $form->setSource($vars);
         // If submitting via email, ensure we have a subject and such
         foreach ($form->getFields() as $field) {
             $fname = $field->get('name');
-- 
GitLab