nick.moult Posted October 9, 2007 Share Posted October 9, 2007 HI, I'm trying to create a php and html script that allows clients to complete questions online and submit them. The questions are completed via multiple choice style radio buttons. The results are subsequently stored in a database. I've included a sample of the script below: <body class="bg" style="margin:20px;"> <form action="<? echo $_SERVER['PHP_SELF']; ?>" name="userinfoform" method="POST"> <h2><p>Please enter the appropriate responses and then click on the submit button:</p></h2> <span style="color:#FF0000"></span> <br> <br/> <table width="603" border="0"> <tr> <td colspan = 9>1. Are Company X complying with your original and ongoing brief (Score from 1-9)?</td> </tr> <tr> <td><input type="radio" name="questionOne" value="1">1<span style="color:#FF0000"></span> </td> <td><input type="radio" name="questionOne" value="2">2<span style="color:#FF0000"></span> </td> <td><input type="radio" name="questionOne" value="3">3<span style="color:#FF0000"></span> </td> <td><input type="radio" name="questionOne" value="4">4<span style="color:#FF0000"></span> </td> <td><input type="radio" name="questionOne" value="5">5<span style="color:#FF0000"></span> </td> <td><input type="radio" name="questionOne" value="6">6<span style="color:#FF0000"></span> </td> <td><input type="radio" name="questionOne" value="7">7<span style="color:#FF0000"></span> </td> <td><input type="radio" name="questionOne" value="8">8<span style="color:#FF0000"></span> </td> <td><input type="radio" name="questionOne" value="9">9<span style="color:#FF0000"></span> </td> </tr> </table> However, what I want to do, before storing the values to a database is run a check that all questions have been completed. I'd imagine that for the "value" i'd step back into PHP where i make the input a variable and check whether or not its been filled in. However, do I have to do that for every input button? I have several questions in this list so it could get messy. Can anyone help? Link to comment https://forums.phpfreaks.com/topic/72472-solved-survey/ Share on other sites More sharing options...
Aureole Posted October 9, 2007 Share Posted October 9, 2007 To check for something use isset(). i.e. <?php if(isset($_POST['something'])) { echo('$_POST[\'something\'] is set.'); } else { echo('$_POST[\'something\'] is NOT set.'); } ?> Link to comment https://forums.phpfreaks.com/topic/72472-solved-survey/#findComment-365425 Share on other sites More sharing options...
pocobueno1388 Posted October 9, 2007 Share Posted October 9, 2007 You will have to check for a completed answer per required question. Here is an example from your example <?php if (!isset($_POST['questionOne'])){ echo "You did not fill question 1 out!"; } else { //They filled everything out, do the next thing } ?> <body class="bg" style="margin:20px;"> <form action="<? echo $_SERVER['PHP_SELF']; ?>" name="userinfoform" method="POST"> <h2><p>Please enter the appropriate responses and then click on the submit button:</p></h2> <span style="color:#FF0000"></span> <table width="603" border="0"> <tr> <td colspan = 9>1. Are Company X complying with your original and ongoing brief (Score from 1-9)?</td> </tr> <tr> <td><input type="radio" name="questionOne" value="1">1<span style="color:#FF0000"></span> </td> <td><input type="radio" name="questionOne" value="2">2<span style="color:#FF0000"></span> </td> <td><input type="radio" name="questionOne" value="3">3<span style="color:#FF0000"></span> </td> <td><input type="radio" name="questionOne" value="4">4<span style="color:#FF0000"></span> </td> <td><input type="radio" name="questionOne" value="5">5<span style="color:#FF0000"></span> </td> <td><input type="radio" name="questionOne" value="6">6<span style="color:#FF0000"></span> </td> <td><input type="radio" name="questionOne" value="7">7<span style="color:#FF0000"></span> </td> <td><input type="radio" name="questionOne" value="8">8<span style="color:#FF0000"></span> </td> <td><input type="radio" name="questionOne" value="9">9<span style="color:#FF0000"></span> </td> </tr> </table> The answer they chose from that question will be stored in $_POST['questionOne'] Link to comment https://forums.phpfreaks.com/topic/72472-solved-survey/#findComment-365429 Share on other sites More sharing options...
nick.moult Posted October 10, 2007 Author Share Posted October 10, 2007 Thanks for the help! Link to comment https://forums.phpfreaks.com/topic/72472-solved-survey/#findComment-366009 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.