views:

53

answers:

2

Hi, I have a simple HTML form which consists of radio buttons where user has to select 1 out of three. Now the Objective is to save the responses of the user, so we admin can view them later. I am more interested in their actual response rather than values field.

here is the sample code

<table border="0"> 
<tr><td><input type="hidden" name="question-11-order" value="0" /><input type="radio" name="question-11-answer" value="1" /></td><td>I am a mixer and mingler at parties.</td></tr> 
<tr><td><input type="radio" name="question-11-answer" value="2" /></td><td>I prefer one-on-one conversations.</td></tr> 
<tr><td><input type="radio" name="question-11-answer" value="3" /></td><td>I'm really in between.</td></tr> 
</table> 
<br /> 


<table border="0"> 
<tr><td><input type="hidden" name="question-39-order" value="0" /><input type="radio" name="question-39-answer" value="1" /></td><td>I derive satisfaction from finishing projects.</td></tr> 
<tr><td><input type="radio" name="question-39-answer" value="2" /></td><td>I derive satisfaction from starting projects.</td></tr> 
<tr><td><input type="radio" name="question-39-answer" value="3" /></td><td>I'm really in between.</td></tr> 
</table> 
<br /> 


<table border="0"> 
<tr><td><input type="hidden" name="question-16-order" value="0" /><input type="radio" name="question-16-answer" value="1" /></td><td>I value realism and common sense.</td></tr> 
<tr><td><input type="radio" name="question-16-answer" value="2" /></td><td>I value imagination and innovation.</td></tr> 
<tr><td><input type="radio" name="question-16-answer" value="3" /></td><td>I'm really in between.</td></tr> 
</table> 
<br /> 
</table> 



<p><input type="submit" name="Submit" value="Send via Email" /></p> 
</form> 

Please help, so to store the results of this form?

+4  A: 

You have to keep track of the actual answer somewhere. For example, an array like so:

$options = array('question-11' => array(
     1=> 'I am a mixer and mingler at parties',
     2=> 'I prefer one-on-one conversations',
     3=> 'I\'m really in between'));

So if you want to find out what the "1" means for question-11, you do something like:

$selected = $_POST['question-11-answer']; // or whatever
$choice = $options['question-11'][$selected];

(This is very crude, but I wanted to make it easy to understand.)

NullUserException
Thanks, your method worked like a charm :D
Gaurish Sharma
A: 

you can make a testpage with this code and point your form towards it:

<pre>
<?php print_r($_POST); ?>
</pre>

Then you can see all the values generated by your form. If you use method GET with your form change $_POST into $_GET