|
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 |
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Mar 07, 2005 9:35 pm Post subject: SmartyValidate: CVS updates |
|
|
There have been some long-coming updates to SmartyValidate in CVS, mainly a way to register your validators from the PHP side and leave the templates purely up to presentation. Without going into a lot of detail, here is a comparison of the "old" way vs. the "new" way. SmartyValidate is backward compatible, but the README has been updated to reflect the new and preferred method.
The old way:
[php:1:1401098dd1]SmartyValidate::connect($smarty);
$smarty->display('index.tpl');[/php:1:1401098dd1]
Code: | {validate field="UserName" criteria="notEmpty" transform="trim" empty="true" halt="true" message="User Name cannot be empty"}
(form goes here) |
The new way:
[php:1:1401098dd1]SmartyValidate::connect($smarty);
SmartyValidate::register_validator('user','UserName','notEmpty',true,true,'trim');
$smarty->display('index.tpl');[/php:1:1401098dd1]
Code: | {validate id="user" message="User Name cannot be empty"}
(form goes here) |
Basically you scrap all of the tags from the template except message, append and assign tags, and a new id tag is introduced, being the validator id given at registration. (Yes, you can make the id the same as the field name to make things easier, but if you have multiple validators on the same field they must have unique ids.)
For validators that act on multiple fields, you pass all the field names separated by colons:
[php:1:1401098dd1]SmartyValidate::register_validator('checkpass','pass1:pass2','isEqual');[/php:1:1401098dd1]
Code: | {validator id="checkpass" message="passwords must be equal"} |
Each additional field is passed to the validate function as field2, field3, etc.
Please test and give me your feedback. I've done quite a bit myself, but extra help is always welcome
Monte |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Tue Mar 08, 2005 12:19 am Post subject: |
|
|
Thanks for the update Monte -- I haven't checked the cvs in awhile. I'm certainly in the camp that thinks this is the proper direction to take. As it happens, I have a new project that I just started which may be able to make use of some of this goodness so I'll likely be checking in at some point with comments regarding my experiences.
Thanks, as always! |
|
Back to top |
|
Spookyfish Smarty Rookie
Joined: 18 Mar 2005 Posts: 8
|
Posted: Sat Mar 19, 2005 10:50 pm Post subject: |
|
|
I'm using the new method from CVS but have found some issues with register_validator().
It seems to dislike being called on every invocation and your examples only call the register_validator() function width _POST is empty.
The is_registered_validator() returns $_x = 0 when a validator at index 0 has been found, however 0 translates to FALSE...
This is with PHP-5.0.4-RC1... _________________ Spookyfish |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Mar 21, 2005 2:40 pm Post subject: |
|
|
Hmm, the register_validator() command unregisters, then re-registers a validator if you try to register an already registered validator. What isn't working? Maybe it should just return false if it is already registered.
As for is_registered_validator(), it returns the indexed position if it finds one. You would have to look for false explicitly:
if(SmartyValidate::is_registered_validator('blah') !== false) { } |
|
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
|