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 not working on non-default form

 
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
uoitguy
Smarty Rookie


Joined: 08 Jul 2006
Posts: 12

PostPosted: Sun Jul 16, 2006 5:24 pm    Post subject: SmartyValidate not working on non-default form Reply with quote

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 Smile


Last edited by uoitguy on Mon Jul 17, 2006 7:04 pm; edited 1 time in total
Back to top
View user's profile Send private message
kills
Smarty Elite


Joined: 28 May 2004
Posts: 493

PostPosted: Mon Jul 17, 2006 4:56 pm    Post subject: Reply with quote

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
View user's profile Send private message
uoitguy
Smarty Rookie


Joined: 08 Jul 2006
Posts: 12

PostPosted: Mon Jul 17, 2006 6:51 pm    Post subject: Reply with quote

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
View user's profile Send private message
uoitguy
Smarty Rookie


Joined: 08 Jul 2006
Posts: 12

PostPosted: Mon Jul 17, 2006 7:05 pm    Post subject: Reply with quote

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
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Mon Jul 17, 2006 8:04 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
uoitguy
Smarty Rookie


Joined: 08 Jul 2006
Posts: 12

PostPosted: Mon Jul 17, 2006 9:01 pm    Post subject: Reply with quote

That is exactly what I have done, and I still receive the same error message.
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Tue Jul 18, 2006 12:39 am    Post subject: Reply with quote

clear your caches and compile files to be certain, that should have fixed it.
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


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

PostPosted: Tue Jul 18, 2006 12:40 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
ronaldo84
Smarty Rookie


Joined: 03 Jul 2006
Posts: 18

PostPosted: Wed Sep 13, 2006 7:31 pm    Post subject: Reply with quote

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
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Wed Sep 13, 2006 8:14 pm    Post subject: Reply with quote

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
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
Page 1 of 1

 
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