View previous topic :: View next topic |
Author |
Message |
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Jun 09, 2004 3:01 pm Post subject: |
|
|
I'm thinking of adding a "halt" parameter. example:
{validate ... field="foo" halt=true message="foo is wrong"}
{validate ... field="bar" halt=true message="bar is wrong"}
{validate ... field="blah" halt=true message="blah is wrong"}
When one validator fails, it would halt execution of any more validators on the form. This way you can get the error message from the first validator if they all would fail.
My question, would it be better to default the value of halt to true or false? In otherwords, when a validator fails, should the rest of the validators be tested (by default) ?
An alternative would be the opposite approach:
{validate ... field="foo" continue=true}
{validate ... field="bar" continue=true}
{validate ... field="blah"}
This implies that validators do not continue (same as halt) by default, and you must specify that they do. |
|
Back to top |
|
hihat Smarty Rookie
Joined: 02 May 2004 Posts: 7
|
Posted: Wed Jun 09, 2004 3:11 pm Post subject: |
|
|
would be a nice feature as well.
I would expect the validation to test all fields as a default (so the user can correct any bad field in one go).
halt better than continue. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Jun 10, 2004 2:40 pm Post subject: |
|
|
2.1 beta 1 is now available from the website. I moved from 2.0 to 2.1 since some features were added.
You can now register objects with SmartyValidate and use them as custom criteria:
// in PHP script
SmartyValidate::connect($smarty);
SmartyValidate::register_object('myobj',$myobj);
SmartyValidate::register_criteria('myobj->foobar');
// in template
{validate ... criteria="isCustom" function="myobj->foobar"}
http://www.phpinsider.com/php/code/SmartyValidate/ |
|
Back to top |
|
hihat Smarty Rookie
Joined: 02 May 2004 Posts: 7
|
Posted: Thu Jun 10, 2004 3:56 pm Post subject: |
|
|
from NEWS
------------
Quote: | "* use message from validator tag instead of session so updates are seen (monte)" |
That's good news. Now I know what I spent my last hour yesterday with.
thanks... |
|
Back to top |
|
xces Smarty Regular
Joined: 09 Apr 2004 Posts: 77
|
Posted: Thu Jun 10, 2004 4:31 pm Post subject: |
|
|
mohrt wrote: | My question, would it be better to default the value of halt to true or false? In otherwords, when a validator fails, should the rest of the validators be tested (by default) ? |
Default it to false, because i would also want to report ALL errors @ once instead of pumping stress into my visitors if they had to enter 20 times a new field
Last edited by xces on Thu Jun 10, 2004 4:42 pm; edited 1 time in total |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Jun 10, 2004 4:40 pm Post subject: |
|
|
Yes, halt defaults to false.
Next release, SmartyValidate will handle arrays of data correctly. Specifically, transformations and criteria will be applied to each element of an array. Criteria will fail if any element fails. Of course, you will be able to specify if you really want the entire array applied to the criteria/transform:
{validate ... criteria="@notEmpty"}
I have it working, just need to clean some things up. |
|
Back to top |
|
xces Smarty Regular
Joined: 09 Apr 2004 Posts: 77
|
Posted: Thu Jun 10, 2004 4:43 pm Post subject: |
|
|
Ehm.. hehe *gulp* i am from holland, can you explain a bit more please? it is a bit technical atm |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Jun 10, 2004 4:45 pm Post subject: |
|
|
xces wrote: |
B.t.w. why do you use |escape in the example documentation? I don't really get the idea of that. |
You should always HTML escape variables that are in form text input or text areas. That way special chars won't screw it up.
Example:
$myvar = This is a "test" yeah
<input type="text" value="{$myvar}">
will result in:
<input type="text" value="This is a "test" yeah">
which of course will not work. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Jun 10, 2004 4:51 pm Post subject: |
|
|
xces wrote: | Ehm.. hehe *gulp* i am from holland, can you explain a bit more please? it is a bit technical atm |
If you have form element like such:
<input type="text" name="foo[]">
<input type="text" name="foo[]">
<input type="text" name="foo[]">
The result will be an array of values. If you apply a validator on that field:
{validate field="foo" transform="trim" criteria="notEmpty"}
Of course you don't want to trim the array, you want the elements trimmed. likewise you don't want to see if the array is empty, you want to see if any of the elements are empty. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Jun 10, 2004 8:41 pm Post subject: |
|
|
There is now a SmartyValidate repository for those that want the bleeding-edge version.
cvs -d :pserver:anonymous@cvs.phpinsider.com:/export/CVS login
cvs -d :pserver:anonymous@cvs.phpinsider.com:/export/CVS checkout SmartyValidate
There is no password, just hit return when prompted for one. |
|
Back to top |
|
xces Smarty Regular
Joined: 09 Apr 2004 Posts: 77
|
Posted: Fri Jun 11, 2004 6:53 am Post subject: |
|
|
[quote="mohrt"] xces wrote: |
You should always HTML escape variables that are in form text input or text areas. That way special chars won't screw it up. |
Yeah i edited my reply allready i've seen it myself yesterday. But is it also needed to escape textareas? |
|
Back to top |
|
electr0n Smarty Rookie
Joined: 26 Mar 2004 Posts: 32 Location: Germany
|
Posted: Fri Jun 11, 2004 1:40 pm Post subject: |
|
|
I've got a question, is the removing of the non validated variables built in now? |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri Jun 11, 2004 1:50 pm Post subject: |
|
|
xces wrote: |
Yeah i edited my reply allready i've seen it myself yesterday. But is it also needed to escape textareas? |
Yes. Try putting </textarea> in the body of your text, see what happens. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri Jun 11, 2004 1:50 pm Post subject: |
|
|
electr0n wrote: | I've got a question, is the removing of the non validated variables built in now? |
Nothing yet. |
|
Back to top |
|
xces Smarty Regular
Joined: 09 Apr 2004 Posts: 77
|
Posted: Sat Jun 12, 2004 11:29 am Post subject: |
|
|
For people who have never used a CVS as a command line tool (like me) go to this site:
https://ccvs.cvshome.org/servlets/ProjectDocumentList?folderID=83&expandFolder=83&folderID=80
And download any stable version. Site is a bit slow, anyway you will get a warning when you first run the command that mohrte has written because you don't have an access file yet. Just ignore it or run it again (like i did) and you won't get an error. Next you can run the update cmd to download the CVS version.
I used "cvs-1-11-14.zip" as my CVS client. |
|
Back to top |
|
|