View previous topic :: View next topic |
Author |
Message |
ThermoDust Smarty Regular
Joined: 10 Sep 2003 Posts: 38
|
Posted: Sun Jun 13, 2004 1:06 am Post subject: SmartyValidate Help |
|
|
Hey, I'm upgrading from an older version and some of the commands have changed. What I am wondering is how to I "register" a form? Can you give an example of smartyvalidate with a registered form?
Command in Question: register_form
Thanks to anyone who replies. |
|
Back to top |
|
ThermoDust Smarty Regular
Joined: 10 Sep 2003 Posts: 38
|
Posted: Sun Jun 13, 2004 1:30 am Post subject: |
|
|
Also, can you show a example of "{$validate.default.is_error}".
I though all I had to do was put it in the template and it'd show either 1 or 0. But that isn't working... |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Sun Jun 13, 2004 2:34 am Post subject: |
|
|
SmartyValidate::register_form('myform');
That will register a form. Then in the template you use:
{validate form="myform" ... }
And when you post the form:
if(SmartyValidate::is_valid($_POST,'myform')) { ... }
will execute if the form info is valid.
The {validate.myform.is_error} is a boolean value, so (I think) it will display "1" when true and "" (not 0) when false. |
|
Back to top |
|
ThermoDust Smarty Regular
Joined: 10 Sep 2003 Posts: 38
|
Posted: Sun Jun 13, 2004 2:37 am Post subject: |
|
|
Okay, do I do the set register_form before or after the if(empty($_POST){
I assume before or just after the connect command... |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Sun Jun 13, 2004 3:06 am Post subject: |
|
|
set it right before displaying the form. each time you call register_form() it essentially "resets" it. (use the latest CVS to be sure, reset_form() was removed) Don't call it between form submits though, just upon the initial form entry (or you leave the form and come back) |
|
Back to top |
|
ThermoDust Smarty Regular
Joined: 10 Sep 2003 Posts: 38
|
Posted: Sun Jun 13, 2004 4:11 am Post subject: |
|
|
Okay, now how do I say the form name? var "fp"? like in older versions or set it in the <form name="" action... |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Sun Jun 13, 2004 6:43 am Post subject: |
|
|
ThermoDust wrote: | Okay, now how do I say the form name? var "fp"? like in older versions or set it in the <form name="" action... |
You only have to put the form name in the validate tags:
{validate form="myform" ... }
After you submit the form, you use is_valid() with the $_POST info :
if ( SmartyValidate::is_valid($_POST, 'myform') ) { ... } |
|
Back to top |
|
ThermoDust Smarty Regular
Joined: 10 Sep 2003 Posts: 38
|
Posted: Sun Jun 13, 2004 8:09 pm Post subject: |
|
|
Is there any way to have it validate using mutiple methods? Like for the password have it match the password and confirm password and have it set a min and max length? |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Jun 14, 2004 2:08 am Post subject: |
|
|
Use multiple {validate ... } tags on the same form element. They are checked in order. |
|
Back to top |
|
xces Smarty Regular
Joined: 09 Apr 2004 Posts: 77
|
Posted: Mon Jun 14, 2004 7:52 am Post subject: |
|
|
You should make a FAQ about this Mohrt |
|
Back to top |
|
|