Jump to content

[SOLVED] Survey


nick.moult

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.