Skip to content
Snippets Groups Projects
Commit 15b9e31d authored by Peter Rotich's avatar Peter Rotich
Browse files

Merge pull request #89 from greezybacon/feature/custom-error


Implement custom validation error

Reviewed-By: default avatarPeter Rotich <peter@osticket.com>
parents 96a86a7f 657dabaa
No related branches found
No related tags found
No related merge requests found
...@@ -447,13 +447,14 @@ class TextboxField extends FormField { ...@@ -447,13 +447,14 @@ class TextboxField extends FormField {
'ip'=>'IP Address', 'number'=>'Number', ''=>'None'))), 'ip'=>'IP Address', 'number'=>'Number', ''=>'None'))),
'validator-error' => new TextboxField(array( 'validator-error' => new TextboxField(array(
'id'=>4, 'label'=>'Validation Error', 'default'=>'', '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')), 'hint'=>'Message shown to user if the input does not match the validator')),
); );
} }
function validateEntry($value) { function validateEntry($value) {
parent::validateEntry($value); parent::validateEntry($value);
$config = $this->getConfiguration();
$validators = array( $validators = array(
'' => null, '' => null,
'email' => array(array('Validator', 'is_email'), 'email' => array(array('Validator', 'is_email'),
...@@ -467,15 +468,17 @@ class TextboxField extends FormField { ...@@ -467,15 +468,17 @@ class TextboxField extends FormField {
// Support configuration forms, as well as GUI-based form fields // Support configuration forms, as well as GUI-based form fields
$valid = $this->get('validator'); $valid = $this->get('validator');
if (!$valid) { if (!$valid) {
$config = $this->getConfiguration();
$valid = $config['validator']; $valid = $config['validator'];
} }
if (!$value || !isset($validators[$valid])) if (!$value || !isset($validators[$valid]))
return; return;
$func = $validators[$valid]; $func = $validators[$valid];
$error = $func[1];
if ($config['validator-error'])
$error = $config['validator-error'];
if (is_array($func) && is_callable($func[0])) if (is_array($func) && is_callable($func[0]))
if (!call_user_func($func[0], $value)) if (!call_user_func($func[0], $value))
$this->_errors[] = $func[1]; $this->_errors[] = $error;
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment