|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
edroms Smarty n00b
Joined: 12 Jan 2012 Posts: 2
|
Posted: Thu Jan 12, 2012 7:28 pm Post subject: Smarty error: validate: validator id not registered |
|
|
Hello -- I have simplified our script/template below. We have had a problem with users not being able to signup for classes using our form on occasion. I've narrowed it down to either cookies not being enabled or the user has clicked the back button previously. Are we not connecting properly? We can easily check for cookies being enabled, but I'm not sure how to fix the "validator id not registered" errors that are being thrown at the time the users encounter this problem. The user just gets the form displayed with no errors indicated. Also, note that this is within a custom Drupal 6 module. Thank you.
The script and template follow:
Code: |
<?php
include_once(SMARTY . '/libs/SmartyValidate.class.php');
function local_class_signup() {
$smarty = &_smarty_get_object();
if (empty($_POST)) {
SmartyValidate::connect($smarty, true);
SmartyValidate::register_validator('firstName', 'firstName', 'notEmpty');
SmartyValidate::register_validator('lastName', 'lastName', 'notEmpty');
return $smarty->fetch(TEMPLATE_DIR . 'training_local.tpl');
}
else {
//data posted from form...
SmartyValidate::connect($smarty);
if (SmartyValidate::is_valid($_POST)) {
SmartyValidate::disconnect();
//do db stuff
// go to the success screen
return $smarty->fetch(TEMPLATE_DIR . 'signup_success.tpl');
} //end smarty isValid else block
else {
$smarty->assign($_POST);
return $smarty->fetch(TEMPLATE_DIR . 'training_local.tpl');
}
}
}
|
Code: |
{* Smarty *}
<label for="firstName">First Name: </label><br />
{validate id="firstName" message='<span class="error">Please enter a first name</span><br />'}
<input type="text" name="firstName" id="firstName" value="{$firstName|escape}" size="45" /><br />
<label for="lastName">Last Name: </label><br />
{validate id="lastName" message='<span class="error">Please enter a last name</span><br />'}
<input type="text" name="lastName" id="lastName" value="{$lastName}" size="45" /><br />
|
|
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Jan 12, 2012 8:11 pm Post subject: |
|
|
one thing I notice, you only test:
if (empty($_POST))
to determine if the form is new or not. What if they hit the enter key reloading the form without a post? it will wipe it out. Maybe test empty $_POST AND also if the form is registered already. |
|
Back to top |
|
edroms Smarty n00b
Joined: 12 Jan 2012 Posts: 2
|
Posted: Mon Jan 23, 2012 10:15 pm Post subject: Resolved - validator id not registered |
|
|
Great catch! I've made the update. We also found that our Drupal installation had caching enabled for performance reasons, so we added the cache exclusion module that specifically disables caching for certain pages. No more issues. Thanks! |
|
Back to top |
|
|
|
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
|