Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
  1. #1
    Junior Member
    Join Date
    Jan 2007
    Posts
    2
    Member #
    14669
    Ok I am a beginner at making websites and I am wondering how I would make someone be forced to fill out a field (in this case it is a checkbox to agree to the terms and conditions) Here is what I have right now


  2.  

  3. #2
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Without looking at your attachment, there are a few ways.

    First off, it is a good idea to let the user know which fields are mandatory. This is mostly done by giving that field an asterix and somewhere near the form state that an asterix(*) means this is a required field.

    To actually ensure they do not miss a field, you would assign that form element to a php variable, trim it, and then check it's length.

    The reason for trimming, is that a smart user could simply fill your field with spaces, so technically the variable could be equal to...
    PHP Code:
    $required $_POST['required_field']; // could be equal to "     " 
    So, do this instead
    PHP Code:
    $required $_POST['required_field'];
    $required trim($required); 
    Then use strlen to check the length. If zero, the field is empty.

    Also, similar can be done in JavaScript, I chose PHP as your extension was .php

  4. #3
    Junior Member
    Join Date
    Jan 2007
    Posts
    2
    Member #
    14669
    Okay so would I just paste that into what I have so far and replace the $required with $termsandconditions ?
    Thanks

  5. #4
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    If terms and donditions is the required field, your code will look something like
    PHP Code:
    $terms $_POST['termsandconditions'];
    $terms trim($terms);
    if(
    strlen($terms) > 0)
     {
        
    // they entered something
     
    }
    else
     {
        
    // they did not.
     

    Assuming your form element is named termsandconditions.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:09 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2020 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com