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 5 of 5
  1. #1
    Member Be Loud Online's Avatar
    Join Date
    Apr 2011
    Location
    GTA, Ontario, Canada
    Posts
    53
    Member #
    27439
    Liked
    7 times
    What I am trying to do is check each question is answered yes or no. If it is not, than I ask the visitor to answer the specific question they missed, and offer them a convenient back button. Then return false to stop the page from progressing...Currently, if the visitor did not answer questions 1, 4 and 8 (for example) it will catch #1, have them go back and answer, resubmit, and then catch #4, have them go back, resubmit, and then catch #6. I would ideally like to have them catch all unanswered, point them all out to the visitor at once.

    Here is the code. One if statement like this for each question (with 50 questions this is the LONG way of doing it)

    PHP Code:
    if (is_null($_POST["no1"]))
      {
      echo 
    "You have not answer Question 1";
      echo 
    "<FORM><INPUT TYPE='button' VALUE='Back' onClick='history.go(-1);return true;'></FORM>";
      return 
    false;
      } 

  2.  

  3. #2
    Junior Member
    Join Date
    Feb 2012
    Posts
    4
    Member #
    30968
    You could use and array to store any errors and only react to them after you've checked all the fields, for example...

    PHP Code:
    <?php
    $error_fields 
    = array();

    // Check field 1
    if (is_null($_POST['no1'])) {
      
    $error_fields[] = 'Question 1';
    }

    // Check field 2
    if (is_null($_POST['no2'])) {
      
    $error_fields[] = 'Question 2';
    }

    // That's all of them, now check for any errors in the array
    if (count($error_fields) > 0) {
      
    // Loop through the errors to display what you want
      
    foreach ($error_fields as $field) {
        echo 
    "You didn't answer " $field;
      }
      
    // the rest of your message, returning and so on...
    }

  4. #3
    Member Be Loud Online's Avatar
    Join Date
    Apr 2011
    Location
    GTA, Ontario, Canada
    Posts
    53
    Member #
    27439
    Liked
    7 times
    Thanks tdous!

  5. #4
    Member Be Loud Online's Avatar
    Join Date
    Apr 2011
    Location
    GTA, Ontario, Canada
    Posts
    53
    Member #
    27439
    Liked
    7 times
    Knowledgable people make it look so easy. lol

  6. #5
    Junior Member
    Join Date
    Feb 2012
    Posts
    4
    Member #
    30968
    Quote Originally Posted by Be Loud Online, post: 231220
    Thanks tdous!
    My pleasure


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:21 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com