From e39f786921feb1adee2e97d678ce4c29ad9013d8 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Mon, 9 Mar 2015 14:17:16 -0500
Subject: [PATCH] forms: Always index the _fields listing

---
 include/class.dynamic_forms.php | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php
index 6793ba2db..3aeba1442 100644
--- a/include/class.dynamic_forms.php
+++ b/include/class.dynamic_forms.php
@@ -715,12 +715,11 @@ class DynamicFormEntry extends VerySimpleModel {
             // Get answers to entries
             foreach ($this->getAnswers() as $a) {
                 if (!($f = $a->getField())) continue;
-                if (isset($this->_fields[$f->get('id')]))
-                    $this->_fields[$f->get('id')] = $f;
-                else { // Perhaps an answer of deleted field
+                // Perhaps an answer of deleted field
+                if (!isset($this->_fields[$f->get('id')])) {
                     $f->setForm($this);
-                    $this->_fields[] = $f;
                 }
+                $this->_fields[$f->get('id')] = $f;
             }
         }
 
@@ -903,7 +902,7 @@ class DynamicFormEntry extends VerySimpleModel {
                 $a->deleted = false;
                 // Add to list of answers
                 $this->_values[] = $a;
-                $this->_fields[] = $field;
+                $this->_fields[$field->get('id')] = $field;
                 $this->_form = null;
 
                 // Omit fields without data
-- 
GitLab