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 issues

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


Joined: 03 Mar 2009
Posts: 32

PostPosted: Mon Mar 16, 2009 6:38 pm    Post subject: SmartyValidate issues Reply with quote

Let's say the form doesn't validate, I fix my input and it submits and I do a back, it causes errors. Warning: Smarty error: validate: validator id 'keyword' is not registered. in /path/libs/Smarty.class.php on line 1092. Is there a way to fix that?

How can I select a form variable after the validation? Should I just go with $_POST vars?
Back to top
View user's profile Send private message
vchris
Smarty Rookie


Joined: 03 Mar 2009
Posts: 32

PostPosted: Tue Mar 17, 2009 1:09 pm    Post subject: Reply with quote

I have a search form, then a results page, then a item specific page. The problem seems to occur when I go down to the item page and do a back. I resubmit the form info and it creates the above errors.

How can I have it so if the user can does a back, he won't have to resend form info and he'll be able to stay on the results page?
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Tue Mar 17, 2009 1:20 pm    Post subject: Reply with quote

After the form is submitted, do an HTTP redirect to the results page. Then the back button will not result in a form resubmit.
Back to top
View user's profile Send private message Visit poster's website
vchris
Smarty Rookie


Joined: 03 Mar 2009
Posts: 32

PostPosted: Tue Mar 24, 2009 6:42 pm    Post subject: Reply with quote

I have a contact page. If I enter the correct data in the fields it'll submit and if I do a back, I get no errors. If I enter incorrect data in the fields, correct the data and resubmit, it'll submit. If I do a back I get these errors:

Warning: Smarty error: validate: validator id 'name' is not registered. in /path/libs/Smarty.class.php on line 1092

Warning: Smarty error: validate: validator id 'email' is not registered. in /path/libs/Smarty.class.php on line 1092

Warning: Smarty error: validate: validator id 'subject' is not registered. in /path/libs/Smarty.class.php on line 1092

Warning: Smarty error: validate: validator id 'message' is not registered. in /path/libs/Smarty.class.php on line 1092

Is there some initialization I need to do somewhere?

Code:

<?php
session_start();

require 'libs/Smarty.class.php';
require 'libs/Trader.class.php';
require 'libs/SmartyValidate.class.php';

$smarty =& new Smarty;
$trader = new Trader;

if(empty($_POST)) {
   // new form, we (re)set the session data
   SmartyValidate::connect($smarty, true);
   // register our validators
   SmartyValidate::register_validator('name', 'name', 'notEmpty',
      false, false, 'trim');
   SmartyValidate::register_validator('email', 'email', 'isEmail',
      false, false, 'trim');
   SmartyValidate::register_validator('subject', 'subject', 'notEmpty',
      false, false, 'trim');
   SmartyValidate::register_validator('message', 'message', 'notEmpty',
      false, false, 'trim');
   // display form
   $smarty->display('contact.tpl');
} else {   
   // validate after a POST
   SmartyValidate::connect($smarty);
   if(SmartyValidate::is_valid($_POST)) {
      // no errors, done with SmartyValidate
      SmartyValidate::disconnect();
      $smarty->display('contact_success.tpl');
      
      // send email
      $trader->send_mail($name, $email, $subject, $message);
   } else {
      // error, redraw the form
      $smarty->assign($_POST);
      $smarty->display('contact.tpl');
   }
}
?>
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Tue Mar 24, 2009 6:46 pm    Post subject: Reply with quote

SmartyValidate::disconnect(); unregisters all validators. If you visit the form again, they need to be reregistered first.
Back to top
View user's profile Send private message Visit poster's website
vchris
Smarty Rookie


Joined: 03 Mar 2009
Posts: 32

PostPosted: Wed Mar 25, 2009 2:04 pm    Post subject: Reply with quote

so how would I fix this issue?

I changed the first line to:
if(empty($_POST) && !SmartyValidate::is_registered_form('contactform')) {

doesn't seem to work.

EDIT: I fixed it with this line:
if(empty($_POST) || !SmartyValidate::is_registered_form('default')) {

Thanks for your help!
Back to top
View user's profile Send private message
mnew707
Smarty n00b


Joined: 13 Mar 2010
Posts: 1

PostPosted: Sat Mar 13, 2010 9:12 pm    Post subject: SmartyValidate issues Reply with quote

I'm dealing with the exact same issue described here. However, when I try the fix in the last thread, I still get the errors when hitting the back button. Here's what I tried:

if(empty($_POST) || !SmartyValidate::is_registered_form('default')) {
if(empty($_POST) || !SmartyValidate::is_registered_form()) {

and tried this syntax:

if(empty($_POST) || !$validator->is_registered_form('default')) {
if(empty($_POST) || !$validator->is_registered_form()) {

Why does it still bomb for me?

I'm thinking of setting a session variable to flag a successful post of form #1 so that when it's revisited after a "back" from form #2, I can tell smarty to treat form #1 as a brand new visit and re-register the variables.

Something like:
$_SESSION['form1'] = "visited"; // I would add this check in the condition for registering the variables

I have tried launching a "sucess" message after good validation in form #1 and providing a redirect button to form #2 but I still get the smarty errors for registering the variable when hitting the "back" button from form #2.

There are multiple forms in this survey so each form is redirected to the next upon sucess with a new script and template.
Back to top
View user's profile Send private message
sayolala
Smarty n00b


Joined: 10 May 2010
Posts: 2

PostPosted: Mon May 10, 2010 8:26 am    Post subject: Reply with quote

Can you post an example of what you are trying to customize? I know there are quite a few places where Able switched to using <asp:Localize> tags. I've done a little research on localization and would like to find out more.
_________________
Grey's anatomy box set
star trek deep space nine dvd
monk seasons dvd box set
Back to top
View user's profile Send private message
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