From 736b0abe44c7e956d30b1c0e2ea8ba090f9fca09 Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Mon, 25 Nov 2013 12:27:28 -0600 Subject: [PATCH] forms: Fix creating ticket without required, internal contact field --- include/class.dynamic_forms.php | 2 +- include/class.forms.php | 4 ++-- include/class.orm.php | 11 ----------- include/class.ticket.php | 35 ++++++++++++++++----------------- open.php | 6 ------ scp/lists.php | 6 ++---- 6 files changed, 22 insertions(+), 42 deletions(-) diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php index 5b7664642..0e529729c 100644 --- a/include/class.dynamic_forms.php +++ b/include/class.dynamic_forms.php @@ -283,7 +283,7 @@ class DynamicFormField extends VerySimpleModel { * field of a custom form. The latter would be isValidEntry() */ function isValid() { - if (count($this->errors()) || !parent::isValid()) + if (count($this->errors())) return false; if (!$this->get('label')) $this->addError( diff --git a/include/class.forms.php b/include/class.forms.php index 4dc69b993..b5e53d9ee 100644 --- a/include/class.forms.php +++ b/include/class.forms.php @@ -23,7 +23,7 @@ class Form { var $title = 'Unnamed'; var $instructions = ''; - var $_errors; + var $_errors = null; var $_source = false; function Form() { @@ -61,7 +61,7 @@ class Form { * boolean true if the field's errors are significant */ function isValid($include=false) { - if (!is_array($this->_errors)) { + if (!isset($this->_errors)) { $this->_errors = array(); $this->getClean(); foreach ($this->getFields() as $field) diff --git a/include/class.orm.php b/include/class.orm.php index 05201c668..be6a46f3e 100644 --- a/include/class.orm.php +++ b/include/class.orm.php @@ -206,17 +206,6 @@ class VerySimpleModel { $i->set($field, $value); return $i; } - - /** - * isValid - * - * Validates the contents of $this->ht before the model should be - * committed to the database. This is the validation for the field - * template -- edited in the admin panel for a form section. - */ - function isValid() { - return true; - } } class SqlFunction { diff --git a/include/class.ticket.php b/include/class.ticket.php index 13fea02f0..ea04eac12 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -1888,12 +1888,28 @@ class Ticket { function create($vars, &$errors, $origin, $autorespond=true, $alertstaff=true) { global $ost, $cfg, $thisclient, $_FILES; + // Don't enforce form validation for email + $field_filter = function($f) use ($origin) { + // Ultimately, only offer validation errors for web for + // non-internal fields. For email, no validation can be + // performed. For other origins, validate as usual + switch (strtolower($origin)) { + case 'email': + return false; + case 'web': + return !$f->get('private'); + default: + return true; + } + }; // Identify the user creating the ticket and unpack user information // fields into local scope for filtering and banning purposes $user_form = UserForm::getUserForm(); $user_info = $user_form->getClean(); - if ($user_form->isValid()) + if ($user_form->isValid($field_filter)) $vars += $user_info; + else + $errors['user'] = 'Incomplete client information'; //Check for 403 if ($vars['email'] && Validator::is_email($vars['email'])) { @@ -1930,20 +1946,6 @@ class Ticket { $field->value = $field->parse($vars[$fname]); } - // Don't enforce form validation for email - $field_filter = function($f) use ($origin) { - // Ultimately, only offer validation errors for web for - // non-internal fields. For email, no validation can be - // performed. For other origins, validate as usual - switch (strtolower($origin)) { - case 'email': - return false; - case 'web': - return !$f->get('private'); - default: - return true; - } - }; if (!$form->isValid($field_filter)) $errors += $form->errors(); @@ -2005,9 +2007,6 @@ class Ticket { || !isset($user_info['email']) || !$user_info['email']) { $user_info = $vars; } - elseif (!$user_form->isValid()) { - $errors['user'] = 'Incomplete client information'; - } //Any error above is fatal. if($errors) return 0; diff --git a/open.php b/open.php index 0035c38e8..927a45349 100644 --- a/open.php +++ b/open.php @@ -38,12 +38,6 @@ if($_POST): $errors += $form->errors(); } } - // Don't process contact information for logged-in clients - if (!$thisclient) { - $contact_form = UserForm::getInstance(); - if (!$contact_form->isValid()) - $errors += $contact_form->errors(); - } if (!$errors && $cfg->allowOnlineAttachments() && $_FILES['attachments']) $vars['files'] = AttachmentFile::format($_FILES['attachments'], true); diff --git a/scp/lists.php b/scp/lists.php index 81cf2663d..fc6f95dbf 100644 --- a/scp/lists.php +++ b/scp/lists.php @@ -13,8 +13,7 @@ if($_POST) { foreach ($fields as $f) if (isset($_POST[$f])) $list->set($f, $_POST[$f]); - if ($list->isValid()) - $list->save(true); + $list->save(true); foreach ($list->getItems() as $item) { $id = $item->get('id'); if ($_POST["delete-$id"] == 'on') { @@ -24,8 +23,7 @@ if($_POST) { foreach (array('sort','value','extra') as $i) if (isset($_POST["$i-$id"])) $item->set($i, $_POST["$i-$id"]); - if ($item->isValid()) - $item->save(); + $item->save(); } break; case 'add': -- GitLab