Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Feb 2008
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Help make CheckBox on Contact Form required

    I have this Contact Form that when submitted sends the Form info successfullt, but I don't know how to make checking the CheckBox required, prior to Submitting the form. Any help will be appreciated.

    Code:
    <form action="../page.php?page=1" method="post" name="contact_us" onSubmit="return capCheck(this);">
    <table cellpadding="5" width="100%">
    <tr>
    <td width="10" class="required_field">*</td>
    <td width="80">Your Name</td>
    <td><input type="text" name="name" maxlength="50" style="width:400px; border: 1px solid #696969;" /><br /><br /></td>
    </tr>
    <tr>
    <td class="required_field">*</td>
    <td><input type="text" name="email" 
    maxlength="40" style="width:400px; border: 1px solid #696969;" /><br /><br /></td>
    </tr>
    <td></td>
    <td>Subject:</td>
    <td><input type="text" name="subject" maxlength="40" style="width:400px; border: 1px solid #696969;"/><br /><br /></td>
    </tr>
    <tr>
    <td></td>
    <td>Comments:</td>
    <td><textarea name="comments" style="width: 400px; height: 250px; background: #F5F5F5; border: 1px solid #F5F5F5;"></textarea><br/><br/></td>
    </tr>
    <tr>
    <td class="required_field">*</td>
    <td>Check Box</td>
    <td><input type="checkbox" value="checked" name="spamblock"><br /><br /></td>
    </tr>
    <td></td>
    </table>
    <br/>
    <br/>
    <p>
    <input type="hidden" name="submited" value="1" />
    <input type="submit" name="submit" value="Submit" style="margin:10px; padding:10px; font-size:10px; font-style:Century-Gothic;" />
    </p>
    </form>

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,680
    Thanks
    6
    Thanked 1,009 Times in 982 Posts
    You don’t make the input required prior to submitting the form, you use PHP to check whether or not the checkbox has been checked after submitting the form, and then either further process the form data or return to the form with a message explaining the reason. You could only enhance this with JavaScript to make it not submit and show a message right away.

    If you are using HTML 5 there is the required attribute which helps in that you don’t need JS. But you still need to check this on the server side because client-side code is not safe from manipulations.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •