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

smartyValidate problem

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

Joined: 30 Apr 2010
Posts: 2

PostPosted: Fri Apr 30, 2010 7:17 pm    Post subject: smartyValidate problem Reply with quote

I'm using smarty validate for my contact form. The form has 4 fields but only 3 are required: name, email, and comments. The problem is that if someone fills in the form and only one of the fields has an error, I get 3 error messages anyways. What do I have to do if I only want error from that specific field printed and not the others. Thanks in advance, the code is as follows:






$smarty = new Smarty;

    if(empty($_POST) || !SmartyValidate::is_registered_form('default')) {
        // new form, we (re)set the session data
        SmartyValidate::connect($smarty, true);
        // register our validators
        SmartyValidate::register_validator('name', 'cfname', 'notEmpty', false, false, 'trim');
        SmartyValidate::register_validator('email', 'cfemail', 'isEmail', false, false, 'trim');
        SmartyValidate::register_validator('comments', 'cfcomments', 'notEmpty', false, false, 'trim');
        // display form
    } else {   
       // validate after a POST
       if(SmartyValidate::is_valid($_POST)) {
           // no errors, done with SmartyValidate
       } else {
           // error, redraw the form




<form name="contact-form" id="contact-form" action="contact.php" method="post" onsubmit="return validateContactForm();">
          <p style="float: right; margin-top: 0px;">
             {validate id="name" message="Name Cannot Be Empty"} <br />
             {validate id="email" message="Email not valid"} <br />
             {validate id="comments" message="Message Cannot Be Empty"}
          <!--messages go here-->
        <h3 id="msg">&nbsp;</h3>

             <label for="cfname">Name:*</label>
             <input name="cfname" id="cfname" type="text" value="{$cfname|escape}"/>
             <label for="cfemail">Email:*</label>
             <input name="cfemail" id="cfemail" type="text" value="{$cfemail|escape}"/>
             <label for="cfwebsite">Website:</label>
             <input name="cfwebsite" id="cfwebsite" type="text" />
             <label for="cfcomments">Message:*</label>
             <textarea name="cfcomments" id="cfcomments" >{$cfcomments|escape}</textarea>
             <input type="submit" name="cfsubmit" id="cfsubmit" value="submit" />
             <input type="reset" name="cfclear" id="cfclear" value="clear" />
Back to top
View user's profile Send private message

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

PostPosted: Fri Apr 30, 2010 8:00 pm    Post subject: Reply with quote

You should only see validation error messages for the fields that are in error. Did you try testing all three fields with different sets of errors and see if you get any different results? Maybe there is a typo in your code, and they all error no matter what?
Back to top
View user's profile Send private message Visit poster's website
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