View previous topic :: View next topic |
Author |
Message |
uoitguy Smarty Rookie
Joined: 08 Jul 2006 Posts: 12
|
Posted: Sun Jul 16, 2006 5:24 pm Post subject: SmartyValidate not working on non-default form |
|
|
I can't seem to get SmartyValidate working with a form other than the default form. Here's a bit of my code below:
PHP:
Code: |
if(empty($_POST)) {
SmartyValidate::connect($smarty, true);
SmartyValidate::register_form('contact', true);
SmartyValidate::register_validator('v1_email', 'email', 'isEmail', false, true, 'trim', 'contact');
$smarty->display('form.tpl');
}
|
Template:
Code: |
<form name="contact" method="post" action="">
<input name="email" type="text">{validate id="v1_email" message="Invalid email address"}
<input name="submit" value="Submit">
</form>
|
Any help would be greatly appreciated! Thanks
Last edited by uoitguy on Mon Jul 17, 2006 7:04 pm; edited 1 time in total |
|
Back to top |
|
kills Smarty Elite
Joined: 28 May 2004 Posts: 493
|
Posted: Mon Jul 17, 2006 4:56 pm Post subject: |
|
|
your {validate} need a reference to the form you have registered...
btw: you only need to register separate forms if you have more than one on a page... |
|
Back to top |
|
uoitguy Smarty Rookie
Joined: 08 Jul 2006 Posts: 12
|
Posted: Mon Jul 17, 2006 6:51 pm Post subject: |
|
|
Doesn't including the form parameter in the register_validator() function take care of specifying the form?
Also, I am registering forms and specifying names because I am unsure at this point how many forms will be on the page and I think it will be easier to address this issue now. |
|
Back to top |
|
uoitguy Smarty Rookie
Joined: 08 Jul 2006 Posts: 12
|
Posted: Mon Jul 17, 2006 7:05 pm Post subject: |
|
|
Okay I have added form="contact" to all my {validate} tags and I am still getting the same error that v1_email is not registered... |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Jul 17, 2006 8:04 pm Post subject: |
|
|
uoitguy wrote: | Okay I have added form="contact" to all my {validate} tags and I am still getting the same error that v1_email is not registered... |
supply the non-default form name.
Code: | {validate form="contact" id="v1_email" message="Invalid email address"} |
|
|
Back to top |
|
uoitguy Smarty Rookie
Joined: 08 Jul 2006 Posts: 12
|
Posted: Mon Jul 17, 2006 9:01 pm Post subject: |
|
|
That is exactly what I have done, and I still receive the same error message. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue Jul 18, 2006 12:39 am Post subject: |
|
|
clear your caches and compile files to be certain, that should have fixed it. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue Jul 18, 2006 12:40 am Post subject: |
|
|
uoitguy wrote: | Doesn't including the form parameter in the register_validator() function take care of specifying the form? |
No, it is possible have two validators the same name on separate forms. |
|
Back to top |
|
ronaldo84 Smarty Rookie
Joined: 03 Jul 2006 Posts: 18
|
Posted: Wed Sep 13, 2006 7:31 pm Post subject: |
|
|
Sorry that i open this case again but i've the same Problem:
My tpl:
Code: |
<form action="" method="post" name="passform">
{validate form="passform" id="old_pass_id" message="Please insert Password"}
<table width="100%">
<tr>
<td width="40%">Old Password:</td>
<td width="60%"><input type="password" name="old_pass" size="45" value=""></td>
</tr>
:
:
</form>
|
And my PHP:
Code: |
if(empty($_POST))
{
SmartyValidate::connect($smarty, true);
SmartyValidate::register_form('passform', true);
SmartyValidate::register_validator('old_pass_id', 'old_pass', 'notEmpty', false, false, 'trim', 'passform');
}
else
{
if($_POST)
{
SmartyValidate::connect($smarty);
if(SmartyValidate::is_valid($_POST))
SmartyValidate::disconnect();
else
{
$smarty->assign($_POST);
//$topic="optionen";
}
}
} |
My cache is clear. But the Messag doesn't appear. Can anybody tell me why? |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Sep 13, 2006 8:14 pm Post subject: |
|
|
You need to pass the form name to is_valid()
Really, you should rarely have a need to set a form name, just use the default. It much less error-prone. form names are in cases you have multiple forms on a page and validating them simultaneously, which should be quite the rarity. I don't think I've ever needed it. If you have multiple forms in a row, just reset() SmartyValidate each time. |
|
Back to top |
|
|