Results 1 to 2 of 2

Thread: Checking Radio Buttons using PHP

  1. #1
    Join Date
    May 2011
    Location
    Burlington, Ontario, Canada
    Posts
    23

    Checking Radio Buttons using PHP

    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. #2
    Join Date
    Sep 2011
    Location
    London, UK
    Posts
    60
    You can do a loop.
    PHP Code:
    $return = array();
    for(
    $i=1$i<=50$i++){
        if (
    is_null($_POST["no".$i])) 
        {
            
    $return[] = $i;
        } 
    }
    if(
    $return){
        echo 
    "You have not answer to Questions: ".implode(', '$return); 
        echo 
    "<FORM><INPUT TYPE='button' VALUE='Back' onClick='history.go(-1);return true;'></FORM>"
    }else{
        
    // everything all right, what next?


Similar Threads

  1. php radio button form for a poll
    By ketanco in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 0
    Last Post: 27 Sep 2008, 04:03 PM
  2. How do I get radio buttons to add a to a number in my database and...
    By qaiphyx in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 1
    Last Post: 27 Feb 2008, 05:29 AM

Tags for this Thread

Posting Permissions

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