From 57eaa549cffad5e322a13323f8bc5ccd0f2f1dcb Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Wed, 15 Oct 2014 12:19:05 -0500
Subject: [PATCH] forms: Fix validation errors for field `name` matches

For fields with `name`s which are the same as other fields on the new ticket
form (such as `time` used with the new ticket by staff form), ensure that
data from the fields outside the main ticket form ("Ticket Details") is not
mingled with fields inside the form.

Since this is only a problem for web requests, and specifically new ticket
by staff requests, this patch only applies the field name to data matching
for non-web requests.
---
 include/class.ticket.php | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/include/class.ticket.php b/include/class.ticket.php
index c4b6d3e94..4345004ee 100644
--- a/include/class.ticket.php
+++ b/include/class.ticket.php
@@ -2368,11 +2368,14 @@ 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');
-            if ($fname && isset($vars[$fname]) && !$field->value)
-                $field->value = $field->parse($vars[$fname]);
+
+        // If submitting via email or api, ensure we have a subject and such
+        if (!in_array(strtolower($origin), array('web', 'staff'))) {
+            foreach ($form->getFields() as $field) {
+                $fname = $field->get('name');
+                if ($fname && isset($vars[$fname]) && !$field->value)
+                    $field->value = $field->parse($vars[$fname]);
+            }
         }
 
         if (!$form->isValid($field_filter('ticket')))
-- 
GitLab