Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Smarty error: validate: validator id not registered

 
Post new topic   Reply to topic    Smarty Forum Index -> Add-ons
View previous topic :: View next topic  
Author Message
edroms
Smarty n00b


Joined: 12 Jan 2012
Posts: 2

PostPosted: Thu Jan 12, 2012 7:28 pm    Post subject: Smarty error: validate: validator id not registered Reply with quote

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


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

PostPosted: Thu Jan 12, 2012 8:11 pm    Post subject: Reply with quote

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


Joined: 12 Jan 2012
Posts: 2

PostPosted: Mon Jan 23, 2012 10:15 pm    Post subject: Resolved - validator id not registered Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    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