Skip to content
Snippets Groups Projects
Commit ea9f0c48 authored by Jared Hancock's avatar Jared Hancock
Browse files

forms: Preserve data for help topic fields

This patch fixes a glitch in the dynamic forms processing system preventing
the validation and capture of data for help topic custom fields. Now the
`$vars` managed inside of `Ticket::create` is connected directly to the
`DynamicFormEntry` created for the data rather than using the magical
connection to `$_POST`.
parent 4827655e
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment