ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Comment Form only validating comments textarea, how do we validate other fields?

January 22, 2012 9:54pm

Subscribe [1]
  • #1 / Jan 22, 2012 9:54pm

    Ben Parizek

    128 posts

    I have a comment form submitting:

    Name
    Email
    Comment

    The only error message I am given if I submit a blank form is:
    “The comment field is required”

    Is there any way to get the other fields to validate as they do on the basic contact form that comes with EE? 

    Otherwise, what’s the best way to validate the other fields on the server side?

  • #2 / Jan 23, 2012 8:22pm

    Dan Decker

    7338 posts

    Hi Ben Parizek,

    What is the result if you fill in the comment area, but leave the other fields blank? Are you alerted that they are required as well? In my testing, if I only filled in the comment area, I recive this error when I try to submit:

    The form you submitted contained the following errors
    
    The name field is required
    The email field is required
    Return to Previous Page

    If you would like a bit more control over form validation you can check out AJAX Form Validator. It has all kinds of options for field validation.

    Let me know what you turn up.

  • #3 / Jan 23, 2012 8:44pm

    Ben Parizek

    128 posts

    Hey Dan,

    I don’t get those errors.  It just submits.  How are you defining those fields in your code?  Here’s what I have…

    {exp:comment:form 
     channel="blog" 
     form_class="standard"
     return="{page_url}#comments"
     }
    
     
      <label>
       <span>Full Name<em>*</em></span>
    
       <input type="text" name="name" />
      </label>
     
     
      <label>
       <span>Email Address<em>*</em></span>
    
       <input type="email" name="email" /><br >
       <em class="note">Your email address will not be displayed publicly.</em>
      </label>
     
     
      <label>
       <span>Comment<em>*</em></span>
    
       <textarea rows="6" cols="20" name="comment"></textarea>
      </label>
     
      
        <label><input type="checkbox" name="notify_me" value="yes" {notify_me} /> Notify me of follow-up comments?</label>
    
      
     <button type="submit">Post Comment</button>
    
    {/exp:comment:form}

    I am using structure but I’ve disable the extension and tested and I’m still seeing the same behavior.

  • #4 / Jan 29, 2012 3:15pm

    Dan Decker

    7338 posts

    Hi Ben,

    I used the code straight out of the User Guide:

    {exp:comment:form channel="standard_channel" form_class="comment-form"}
    
    
            {if logged_out}
                    <label for="name">Name:</label> <input type="text" name="name" value="{name}" size="50" /><br >
                    <label for="email">Email:</label> <input type="text" name="email" value="{email}" size="50" /><br >
                    <label for="location">Location:</label> <input type="text" name="location" value="{location}" size="50" /><br >
                    <label for="url">URL:</label> <input type="text" name="url" value="{url}" size="50" /><br >
            {/if}
    
            <label for="comment">Comment:</label>
    
            <textarea name="comment" cols="70" rows="10">{comment}</textarea>
            <label><input type="checkbox" name="save_info" value="yes" {save_info} /> Remember my personal information</label>
    
            <label><input type="checkbox" name="notify_me" value="yes" {notify_me} /> Notify me of follow-up comments?</label>
    
    
            {if captcha}
                    <label for="captcha">Please enter the word you see in the image below:</label>
    
                    {captcha}
    
                    <input type="text" name="captcha" value="{captcha_word}" maxlength="20" /></p>
            {/if}
    
    <input type="submit" name="submit" value="Submit" />
    
    {/exp:comment:form}

    The major differences I see between what I have and what you have are the inclusion of some variables in my form. I’ll mark those differences below:

    {exp:comment:form 
     channel="blog" 
     form_class="standard"
     return="{page_url}#comments"
     }
    
     
      <label>
       <span>Full Name<em>*</em></span>
    
       <input type="text" name="name" value="{name}" />
      </label>
     
     
      <label>
       <span>Email Address<em>*</em></span>
    
       <input type="email" name="email" value="{email}" /><br />
       <em class="note">Your email address will not be displayed publicly.</em>
      </label>
     
     
      <label>
       <span>Comment<em>*</em></span>
    
       <textarea rows="6" cols="20" name="comment">{comment}</textarea>
      </label>
     
      
        <label><input type="checkbox" name="notify_me" value="yes" {notify_me} /> Notify me of follow-up comments?</label>
    
      
     <button type="submit" name="submit">Post Comment</button>
    
    {/exp:comment:form}

    To wit, I added the {name}, {email} and {comment} variables to the correct form elements and added name=“submit” to your submit button.

    Give that code a whirl and let me know if you get the errors as expected.

    Cheers!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases