From 657dabaa00d72add9a3cd1397a1848d06d65ca39 Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Mon, 4 Nov 2013 21:51:22 +0000 Subject: [PATCH] Implement custom validation error Fixes #78 --- include/class.forms.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/include/class.forms.php b/include/class.forms.php index 356c504da..b1ddaa806 100644 --- a/include/class.forms.php +++ b/include/class.forms.php @@ -447,13 +447,14 @@ class TextboxField extends FormField { 'ip'=>'IP Address', 'number'=>'Number', ''=>'None'))), 'validator-error' => new TextboxField(array( 'id'=>4, 'label'=>'Validation Error', 'default'=>'', - 'configuration'=>array('size'=>40), + 'configuration'=>array('size'=>40, 'length'=>60), 'hint'=>'Message shown to user if the input does not match the validator')), ); } function validateEntry($value) { parent::validateEntry($value); + $config = $this->getConfiguration(); $validators = array( '' => null, 'email' => array(array('Validator', 'is_email'), @@ -467,15 +468,17 @@ class TextboxField extends FormField { // Support configuration forms, as well as GUI-based form fields $valid = $this->get('validator'); if (!$valid) { - $config = $this->getConfiguration(); $valid = $config['validator']; } if (!$value || !isset($validators[$valid])) return; $func = $validators[$valid]; + $error = $func[1]; + if ($config['validator-error']) + $error = $config['validator-error']; if (is_array($func) && is_callable($func[0])) if (!call_user_func($func[0], $value)) - $this->_errors[] = $func[1]; + $this->_errors[] = $error; } } -- GitLab