|
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 |
kabatak Smarty Rookie
Joined: 06 Mar 2004 Posts: 33
|
Posted: Fri Apr 01, 2005 12:34 pm Post subject: SmartyValidate |
|
|
Hi, is it possible for a validation to only occur when another field is not empty?
For example: If field 1 is not empty, the validation for field 2 must occur.
Else, if field 1 is empty, the validation for field 2 should not occur.
Thanks, |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri Apr 01, 2005 2:37 pm Post subject: |
|
|
You can create a custom validator to do whatever you want. There isn't one that comes with SmartyValidate to do this specifically. |
|
Back to top |
|
kabatak Smarty Rookie
Joined: 06 Mar 2004 Posts: 33
|
Posted: Fri Apr 01, 2005 2:39 pm Post subject: |
|
|
I see, thanks. |
|
Back to top |
|
walterly Smarty n00b
Joined: 16 Apr 2005 Posts: 2
|
Posted: Sat Apr 16, 2005 5:34 am Post subject: |
|
|
Hi,
I am facing a problem when trying to do more than one validation on username and i have the following:
register.php
Code: |
SmartyValidate::register_validator('v_username1', 'username', 'notEmpty', false, false, 'trim');
SmartyValidate::register_validator('v_username2', 'username', 'isValidUser', false, false, 'trim');
|
and regsiter.tpl
Code: |
{validate id="v_username1" message="username cannot be empty"}
{validate id="v_username2" message="username already exists"} |
And the custom validate_criteria.isValidUser.php
Code: |
function smarty_validate_criteria_isValidUser($value, $empty, &$params, &$formvars){
if(strlen($value) == 0)
return $empty;
global $userlib;
if($userlib->UserExists($value) ) {
//if user exists, UserExists will return true, we'll return false to smartyvalidate
// UserExists function tested to be working correctly
return false;
}
return true;
}
|
If i submit any username or currently existance username, it work fine.
The problem i have is, if i start the form by submitting an empty username filed, i got both the error msg of username cannot be empty (v_username1) and username already exist (v_username2). Any idea where i went wrong? |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Sat Apr 16, 2005 5:33 pm Post subject: |
|
|
you need "true" for the halt parameter on the first one. |
|
Back to top |
|
walterly Smarty n00b
Joined: 16 Apr 2005 Posts: 2
|
Posted: Sat Apr 16, 2005 5:44 pm Post subject: |
|
|
mohrt wrote: | you need "true" for the halt parameter on the first one. |
This would mean no further check or error will be display if username field is empty. I was thinking of displaying all the different field error messages at one go irregardless of empty or filled username. Guess i will adapt the halt if empty option. thanks.
--
wally |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Sun Apr 17, 2005 3:58 am Post subject: |
|
|
If you want to collect all the errors, use append.
{validate ... append="foo"}
{validate ... append="foo"}
then loop over $foo |
|
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
|