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 2.4 released
Goto page 1, 2  Next
 
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
mohrt
Administrator


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

PostPosted: Mon Apr 04, 2005 3:30 pm    Post subject: SmartyValidate 2.4 released Reply with quote

This is a major update, most notably the validation registration has been moved to PHP with register_validator(), leaving the template function 100% presentational (no validator criteria in the template.) SmartyValidate now supports forms across multiple pages, see the set_page() function.

The documentation has been updated to reflect the new method of registering validators. Although the old method is still backward compatible, it is no longer documented. A lot of things in the README have been marked as "deprecated", and may be fully removed in future versions.


* fix ccExpDate criteria bug, it didn't work (monte)
* add set_page() function, update README (monte)
* add register_validator() function, update README (monte)
* fix documentation on custom criteria/transforms (monte)
* add support for specific array keys field="foo[bar]" (monte)
* allow array brackets field=foo[] (monte)
* add better error reporting when connect() was not called (monte)


http://www.phpinsider.com/php/code/SmartyValidate/


Last edited by mohrt on Tue May 17, 2005 1:53 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
netnamues
Smarty Rookie


Joined: 29 Dec 2004
Posts: 30

PostPosted: Tue Apr 05, 2005 9:31 pm    Post subject: Reply with quote

So am I correct in saying I still need something like

Code:
{validate id="fname" message="Full Name cannot be empty" append="errors"}
{validate id="lname" message="Last Name cannot be empty" append="errors"}
{validate id="email" message="Email must be a valid email address" append="errors"}
{validate id="billAddress1" message="Billing Address1 cannot be blank" append="errors"}
{validate id="billCity" message="Billing City cannot be blank" append="errors"}
{validate id="billState" message="Billing State cannot be blank" append="errors"}
{validate id="billZip" message="Billing Zip cannot be blank" append="errors"}
{validate id="billPhone" message="Billing Phone cannot be blank" append="errors"}
{validate id="password" message="Passwords must match" append="errors"}


in my template file to set the message and append to errors?

Is there a way to do this in the php code?

btw... LOVE the idea of moving the validation into the code layer!
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Tue Apr 05, 2005 9:40 pm    Post subject: Reply with quote

That is correct. There is currently no method of setting error messages from the PHP code (since this is presentation), or appending them to a template variable. You can however use config files to manage error messages.

errors.conf

Code:
name_empty = "You must supply a name"
passwd_empty = "You must supply a password"


template:

Code:
{config_load file="errors.conf"}
{validate id="foo" message=#name_empty#}
Back to top
View user's profile Send private message Visit poster's website
kills
Smarty Elite


Joined: 28 May 2004
Posts: 493

PostPosted: Wed Apr 06, 2005 8:19 am    Post subject: Reply with quote

Hi monte,

little typo on your description page:

Quote:

DOWNLOAD:

Stable 2.3 (April 4, 2005):
SmartyValidate-2.4.tar.gz


Thanks,
Markus
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Wed Apr 06, 2005 1:48 pm    Post subject: Reply with quote

got it, thanks
Back to top
View user's profile Send private message Visit poster's website
2344223
Smarty Rookie


Joined: 31 Oct 2004
Posts: 5

PostPosted: Wed Apr 13, 2005 3:34 pm    Post subject: Reply with quote

hi mohrt. thanks for this addon. i like it.

one problem:

if i validate an email adress and someone types in:

test@test

i dont get an error message. but this is no valid emailadress. the ".de" or ".com" etc is missing.

isnt it possible to make it an error if someone types in sth. like

test@test or 123@123


thanks for help.
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Wed Apr 13, 2005 4:08 pm    Post subject: Reply with quote

Yes, this has been a problem. I changed the logic in CVS to the one below, give it a try:

Code:
function smarty_validate_criteria_isEmail($value, $empty, &$params, &$formvars) {

    if(strlen($value) == 0)
        return $empty;

    // in case value is several addresses separated by newlines
    $_addresses = preg_split('![\n\r]+!', $value);

    foreach($_addresses as $_address) {
      $_ret = !(preg_match('!@.*@|\.\.|\,|\;!', $_address) ||
           !preg_match('!^.+\@(\[?)[a-zA-Z0-9\.\-]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$!', $_address));
       
        if(!$_ret)
            return $_ret;
    }
    return true;
}
Back to top
View user's profile Send private message Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Apr 13, 2005 5:20 pm    Post subject: Reply with quote

To be pendantic, (and I think this has been pointed out before) test@test is a valid email address -- but it is not an internet addressable email address. It can however be addressable from an intranet.
Back to top
View user's profile Send private message
2344223
Smarty Rookie


Joined: 31 Oct 2004
Posts: 5

PostPosted: Wed Apr 13, 2005 6:17 pm    Post subject: Reply with quote

mohrt wrote:
Yes, this has been a problem. I changed the logic in CVS to the one below, give it a try:

Code:
function smarty_validate_criteria_isEmail($value, $empty, &$params, &$formvars) {

    if(strlen($value) == 0)
        return $empty;

    // in case value is several addresses separated by newlines
    $_addresses = preg_split('![\n\r]+!', $value);

    foreach($_addresses as $_address) {
      $_ret = !(preg_match('!@.*@|\.\.|\,|\;!', $_address) ||
           !preg_match('!^.+\@(\[?)[a-zA-Z0-9\.\-]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$!', $_address));
       
        if(!$_ret)
            return $_ret;
    }
    return true;
}



thanks mohrt. works fine now. Very Happy


@boots

yes you are right. but i am sure most of the user are using the validation class for smarty not for intranet sites or sth. similiar. so it is more interesting that the email is like: mail@site.com and not mail@site

thanks again mohrt. i like your work very much. smarty does good work!

btw. sorry for my bad english.
Back to top
View user's profile Send private message
Sybux2000
Smarty Rookie


Joined: 27 Feb 2005
Posts: 13

PostPosted: Thu Apr 14, 2005 7:56 pm    Post subject: Reply with quote

I've got an error when enabling smarty debugging.

On each field that I want to validate, I've got the following message :

Code:
<br /><b>Notice</b>:  Undefined index:  gamename in <b>k:\dev\smarty\templates_c\%%A2^A29^A29637C5%%game_add.tpl.php</b> on line <b>20</b><br />


As soon as I turn off debug, all is working.
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Thu Apr 14, 2005 8:08 pm    Post subject: Reply with quote

What does the source of that template look like? is it smartyvalidate giving the notice, or something else?

debugging is supposed to show notices (not necessarily an error), so that is not uncommon.
Back to top
View user's profile Send private message Visit poster's website
Sybux2000
Smarty Rookie


Joined: 27 Feb 2005
Posts: 13

PostPosted: Thu Apr 14, 2005 8:43 pm    Post subject: Reply with quote

Oops...

So I think I've not understand well the debug function.

All is working ok so... I think I should go to bed and stop coding à 11PM !!
Back to top
View user's profile Send private message
kabatak
Smarty Rookie


Joined: 06 Mar 2004
Posts: 33

PostPosted: Mon Apr 18, 2005 5:49 pm    Post subject: Re: SmartyValidate 2.4 released Reply with quote

mohrt wrote:
Although the old method is still backward compatible, it is no longer documented. A lot of things in the README have been marked as "deprecated", and may be fully removed in future versions.

Please don't removed the backwards compatibility. I don't know but I am more comfortable in the old style. I think having the validation in the PHP layer is a little bit more confusing IMHO.

Having the validation in templates with attributes like "name=value" is much more easier than "SmartyValidate::register_validator('v_initdate','StartDate','dummyValid',false,false,'makeDate')" inside PHP. The parameters can be confusing, at least for a novice coder. Templates are suppose to be used by designers who know less about programming so this might be a litlle hard for them.

Also, the new method is quite redundant. You still have to put {validate id="v_initdate"} inside the template after putting SmartyValidate::register_validator('v_initdate', 'StartDate', 'dummyValid', false, false, 'makeDate'); inside PHP. In the old way, you only need to put the validation once inside the template so it's easier.

What I do in my scripts is that I separate the validation files and just include them in the main template like: {include file="validator.tpl"}. This way you can separate all the validation code from the main template.

So I suggest please do not remove the old style in the future versions. Thanks. Good job still for SmartyValidate.
Back to top
View user's profile Send private message
kabatak
Smarty Rookie


Joined: 06 Mar 2004
Posts: 33

PostPosted: Mon Apr 18, 2005 6:10 pm    Post subject: Reply with quote

btw, do you still have a copy of the old docs? thanks.
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Mon Apr 18, 2005 9:10 pm    Post subject: Re: SmartyValidate 2.4 released Reply with quote

kabatak wrote:

Having the validation in templates with attributes like "name=value" is much more easier than "SmartyValidate::register_validator('v_initdate','StartDate','dummyValid',false,false,'makeDate')" inside PHP. The parameters can be confusing, at least for a novice coder. Templates are suppose to be used by designers who know less about programming so this might be a litlle hard for them.


The validation criteria is something the template designer should not be concerned with. They only deal with the validation messages and presentation of them. That is why it was decided to move the criteria to the application side where it belongs.

kabatak wrote:

Also, the new method is quite redundant. You still have to put {validate id="v_initdate"} inside the template after putting SmartyValidate::register_validator('v_initdate', 'StartDate', 'dummyValid', false, false, 'makeDate'); inside PHP. In the old way, you only need to put the validation once inside the template so it's easier.


The "v_initdate" is the ID tag, it is what you use to correspond to the correct validator from the template. That isn't redundant, that ID tag was put there for this exact purpose. In the template you have two simple things: the ID and the message. The rest goes application side.

With criteria in the template, the template designer can hose up the validation by removing/changing it. With the new method, only the presentation of the validation messages can be changed from the template. The criteria itself (application logic) is moved to where it should be.

kabatak wrote:

What I do in my scripts is that I separate the validation files and just include them in the main template like: {include file="validator.tpl"}. This way you can separate all the validation code from the main template.


Yep, that is quite doable from the new method as well. We are only moving the criteria out of the template, you can still handle the message presentation from another template if you wish.

kabatak wrote:

So I suggest please do not remove the old style in the future versions. Thanks. Good job still for SmartyValidate.


The new method is going to be the recommended and documented way to use SmartyValidate. The old method although deprecated still works.

kabatak wrote:

btw, do you still have a copy of the old docs? thanks.


You can get the old documenation from an old release, just change the release version in the download link, the files are still there.
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
Goto page 1, 2  Next
Page 1 of 2

 
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