diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php index c0a203646ffd02170cf4c5a1eff44778687722d8..050c8f3305635db0263018acac50f4c4805fc7eb 100644 --- a/include/class.dynamic_forms.php +++ b/include/class.dynamic_forms.php @@ -519,6 +519,7 @@ class DynamicFormEntry extends VerySimpleModel { var $_form; var $_errors = false; var $_clean = false; + var $_source = null; function getId() { return $this->get('id'); @@ -572,12 +573,21 @@ class DynamicFormEntry extends VerySimpleModel { function getFields() { if (!isset($this->_fields)) { $this->_fields = array(); - foreach ($this->getAnswers() as $a) - $this->_fields[] = $a->getField(); + foreach ($this->getAnswers() as $a) { + $T = $this->_fields[] = $a->getField(); + $T->setForm($this); + } } return $this->_fields; } + function getSource() { + return $this->_source ?: (isset($this->id) ? false : $_POST); + } + function setSource($source) { + $this->_source = $source; + } + function getField($name) { foreach ($this->getFields() as $field) @@ -768,8 +778,8 @@ class DynamicFormEntry extends VerySimpleModel { if (count($this->dirty)) $this->set('updated', new SqlFunction('NOW')); parent::save(); - foreach ($this->getAnswers() as $a) { - $field = $a->getField(); + foreach ($this->getFields() as $field) { + $a = $field->getAnswer(); if ($this->object_type == 'U' && in_array($field->get('name'), array('name','email'))) continue; diff --git a/include/class.ticket.php b/include/class.ticket.php index 6518d12eae5722401bb1f96a4932ed00e14473c0..b2967f28851452cbb08df9098ab98bbfc9606d7f 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -2307,9 +2307,11 @@ class Ticket { if ($vars['topicId'] && ($topic=Topic::lookup($vars['topicId']))) { if ($topic_form = $topic->getForm()) { + $TF = $topic_form->getForm($vars); $topic_form = $topic_form->instanciate(); - if (!$topic_form->getForm()->isValid($field_filter('topic'))) - $errors = array_merge($errors, $topic_form->getForm()->errors()); + $topic_form->setSource($vars); + if (!$TF->isValid($field_filter('topic'))) + $errors = array_merge($errors, $TF->errors()); } } @@ -2338,6 +2340,9 @@ class Ticket { if(!Validator::process($fields, $vars, $errors) && !$errors['err']) $errors['err'] ='Missing or invalid data - check the errors and try again'; + if ($vars['topicId'] && !$topic) + $errors['topicId'] = 'Invalid help topic selected'; + //Make sure the due date is valid if($vars['duedate']) { if(!$vars['time'] || strpos($vars['time'],':')===false)