|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
BrokenFrame Smarty n00b
Joined: 17 Apr 2007 Posts: 3
|
Posted: Tue Apr 17, 2007 5:36 pm Post subject: Multiple validator for a single form field |
|
|
I am strugling with multiple validators for a same form field which results in one error message at a time when the form field does not matches the validator rules.
Let me show the case briefly:
Smarty template file:
Code: | <INPUT NAME="field1" TYPE="TEXT" />
{validate id="rule_1" message="Field can not be empty"}
{validate id="rule_2" message="Field is not a number"}
...template implements other form input fields and validator... |
PHP code fragment:
Code: | SmartyValidate::connect($smarty, true);
// syntax: SmartyValidate::register_validator($validator id, $formname, $validator, $empty, $halt, $transform)
SmartyValidate::register_validator('rule_1', 'field1', 'notEmpty', false, false, 'trim');
SmartyValidate::register_validator('rule_2', 'field1', 'isInt', true, false, 'trim');
SmartyValidate::register_validator('another_field', 'another_field', 'isEmpty', false, false, 'trim'); |
Desired result:
1. If field is empty: output message: 'Field can not be empty' (do not output message 2)
2. If field is not a number: output message 'Field is not a number'
3. Other validator output...
If the form is posted completely unfilled then:
rule 1 fails due to $empty = false
rule 2 succeeds even though field1 isn't numerical, due to $empty = true
Remember I do want to show two different validation message, so only use rule 2 with $empty = false is not an option in my case.
Actually result:
empty form field posted: shows validation message 1 + 2 (UNCORRECT, WHY?)
non-numerical form field posted: shows validation message 2(CORRECT)
numerical form field posted: no validation message occures (CORRECT)
Can anyone explain where it goes wrong?
Other point of interest:
How do you manage multiple validation error messages for a single form field in your smarty templates. Assign all the output to smarty vars and show only the significant message using a lot of {if} {else} branches ?
Looking forward for some hints about this.
Kind regards,
Broken Frame |
|
Back to top |
|
BrokenFrame Smarty n00b
Joined: 17 Apr 2007 Posts: 3
|
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|