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 "once fail, fail for all" for one f

 
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
tangfucius
Smarty Rookie


Joined: 30 Sep 2004
Posts: 16

PostPosted: Fri Jun 10, 2005 3:17 pm    Post subject: SmartyValidate "once fail, fail for all" for one f Reply with quote

As stated in the FEATURES:
FEATURES:

Quote:
...
Multiple validators may be used for one field. Once one validator fails,
the remaining validators for that field are ignored.
...


This might be better off be an user option that can be set, for example,
in a situation where there are multiple validators on one field "username",
there are 3 validators, notEmpty, isRegExp, isUnique. I've registered the validators isRegExp and isUnique as allow empty values, however when the notEmpty validator fails, the error messages related to the isRegExp and isUnique validators show up as well as the notEmpty error msg because SmartyValidate skipped the validation on the username field and flagged the skipped validators as failed. This is not a desired result in many situations. You don't want the error message to say "This field cannot be empty" and also "This field can only contain numbers, characters and underscores" because there is simply no reason to show the later error message. The optimal logic should be that if a field is doomed invalid, it could skip the other validators but not flag them as failed validations. What are you thoughts, mohrt?
Back to top
View user's profile Send private message
mckneisler
Smarty n00b


Joined: 24 Aug 2006
Posts: 3

PostPosted: Fri Aug 25, 2006 8:18 pm    Post subject: Reply with quote

I believe that this is the same issue as the Topic I started here:
http://www.phpinsider.com/smarty-forum/viewtopic.php?t=8744

My solution right now was to modify the class code within the "_failed_fields" function as such:
Code:

            if(is_array($_ret) && in_array($_full_field, $_ret)) {
                // already failed, skip this test
                $_sess[$_key]['valid'] = 1;  // added this line
                continue;   
            }


What this does is skips further validation on the field in error without posting messages from subsequent validators.

I think the true proper fix should allow for a parameter to be passed to the "is_valid" method as to how to handle subsequent validators on a field once one has failed, or to allow a parameter to be passed to the "register_validator" method that specifies that this validation should occur even if a prior validation failed. Or possibly a combination of both.

Any thoughts?
Back to top
View user's profile Send private message
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