Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

SmartyValidate

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Add-ons
View previous topic :: View next topic  
Author Message
kabatak
Smarty Rookie


Joined: 06 Mar 2004
Posts: 33

PostPosted: Fri Apr 01, 2005 12:34 pm    Post subject: SmartyValidate Reply with quote

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
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Fri Apr 01, 2005 2:37 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
kabatak
Smarty Rookie


Joined: 06 Mar 2004
Posts: 33

PostPosted: Fri Apr 01, 2005 2:39 pm    Post subject: Reply with quote

I see, thanks.
Back to top
View user's profile Send private message
walterly
Smarty n00b


Joined: 16 Apr 2005
Posts: 2

PostPosted: Sat Apr 16, 2005 5:34 am    Post subject: Reply with quote

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
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Sat Apr 16, 2005 5:33 pm    Post subject: Reply with quote

you need "true" for the halt parameter on the first one.
Back to top
View user's profile Send private message Visit poster's website
walterly
Smarty n00b


Joined: 16 Apr 2005
Posts: 2

PostPosted: Sat Apr 16, 2005 5:44 pm    Post subject: Reply with quote

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
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Sun Apr 17, 2005 3:58 am    Post subject: Reply with quote

If you want to collect all the errors, use append.

{validate ... append="foo"}
{validate ... append="foo"}

then loop over $foo
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Add-ons All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP