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 -> new Validators ignored - old ones chose

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


Joined: 24 Jul 2006
Posts: 21

PostPosted: Tue Aug 22, 2006 9:49 am    Post subject: SmartyValidate -> new Validators ignored - old ones chose Reply with quote

Heya - i have the following validation logic for different forms that are displayed one after another through one php-class:

[php:1:43ff02986c]
if(empty($_POST)) {
SmartyValidate::connect($smarty, true);
SmartyValidate::register_validator(myValidator1);
SmartyValidate::register_validator(myValidator2);
SmartyValidate::register_validator(myValidator3);
$smarty->display('mytempl_1.tpl');
}else{
SmartyValidate::connect($smarty);

if ($_POST['step'] == 2){
if(SmartyValidate::is_valid($_POST)) {
SmartyValidate::disconnect(); // disconnect to get rid of old validators
SmartyValidate::connect($smarty); // new connect after getting rid of old validators

SmartyValidate::register_validator(myValidator4);
SmartyValidate::register_validator(myValidator5);
SmartyValidate::register_validator(myValidator6);

$smarty->display('mytempl_2.tpl');
}else{
//redisplay form 1
$smarty->assign($_POST);
$smarty->display('mytempl_1.tpl');
}

}

if ($_POST['step'] == 3){
if(SmartyValidate::is_valid($_POST)) {
SmartyValidate::disconnect(); // disconnect to get rid of old validators
SmartyValidate::connect($smarty); // new connect after getting rid of old validators

SmartyValidate::register_validator(myValidator7);
SmartyValidate::register_validator(myValidator8);
SmartyValidate::register_validator(myValidator9);

$smarty->display('mytempl_3.tpl');
}else{
//redisplay form 2
$smarty->assign($_POST);
$smarty->display('mytempl_2.tpl'); // <------- HERE IT HAPPENS - OLD VALIDATORS (myValidator1-3) BACK IN $_SESSION
}

}

}
[/php:1:43ff02986c]

Now when Form 1 is displayed, [SmartyValidate] in $_SESSION is perfectly filled with my validators (myValidator1-3). Validation works great and Form2 will be shown if the form is valid.

When Form 2 is displayed, [SmartyValidate] in $_SESSION is perfectly filled with my new validators (myValidator4-6). But when i submit the form with invalid values, mytempl_2.tpl will display but shows errors on missing validators: "Warning: Smarty error: validate: validator id 'myValidatorID' is not registered."

And in fact - [SmartyValidate] in $_SESSION suddenly shows my old validators (myValidator1-3) at this point ???.
How can that happen ???
Why are my old validators back at that point ?!?!?!
Why are my new Validators lost ?
Why does it work for Step 1 but nor for Step 2 ?

Thanks so much for any hints !!!!
Back to top
View user's profile Send private message
tdmf
Smarty Rookie


Joined: 24 Jul 2006
Posts: 21

PostPosted: Mon Sep 11, 2006 8:14 am    Post subject: Reply with quote

330 views and not 1 reply.......

impressive - did i chose the wrong forum ?
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Mon Sep 11, 2006 3:09 pm    Post subject: Reply with quote

make sure you reset() the validation class between forms (or steps), or use separate form ids, or assing all validators and use the 'page' features.
Back to top
View user's profile Send private message Visit poster's website
tdmf
Smarty Rookie


Joined: 24 Jul 2006
Posts: 21

PostPosted: Mon Sep 11, 2006 5:25 pm    Post subject: Reply with quote

i tried exactly what you suggested Wink
No success - my solution was to put everything in different functions - which is a pain in the butt.....
Im close to thinking this has to do with the 64Bit Memory prob of php - as this is running on osx.....
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