Hi Everyone,
I have a set of radio buttons and I am using 'weedpackets' approach on defining them as an array, then checking the results. My method of storing the data in my table may be the source of my confusion, but I will explain and I am open to suggestions here.
The dilema I am having is this...
On the form, I have Grades 7-12 and need to limit the chosen radio button so only one can ever be selected. I check which is selected and then store the value 'Grade 7' thru 'Grade 12' in the fields named 'Grade 7' thru 'Grade 12' with the data the same name. I did this for ease of use when I am generating info for the sales and marketing staff.
IE I do a lookup and show everyone who is in 'Grade 12' .
Now I know I cold just store a 0 or 1 in those fields, but the sales staff sometimes need me to do a CSV dump for them to import the data into a Contacts Management program and they would not know what a 0 or 1 represents. (believe it or not) So I store the actual grade name in a field called such.
With that explained, here is my code for the form...
<td align="center" valign="top">
<p align="left" class="font style1"><font size="3">Your grade level:<br>
<input value="Grade 7" name="GradeLevel[0]" type="radio" tabindex="15">7
<input value="Grade 8" name="GradeLevel[1]" type="radio" tabindex="16">8
<input value="Grade 9" name="GradeLevel[2]" type="radio" tabindex="17">9
<input value="Grade 10" name="GradeLevel[3]" type="radio" tabindex="18">10
<input value="Grade 11" name="GradeLevel[4]" type="radio" tabindex="19">11
<input value="Grade 12" name="GradeLevel[5]" type="radio" tabindex="20">12<br>
<img src="essaysubmit_files/space.gif" border="0" height="10" width="1"></font></p>
</td>
and in the process page...
// Check and see if they clicked on at least one Grade Level
if(!isset($_POST['GradeLevel'])) { // You did not select any boxes
$_POST['GradeLevel'] = array();// Make it an array
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>You did not select a Grade Level. <br>Please hit the back button and choose a Grade Level.</font></p>"); // Go back
} else {
foreach ($_POST['GradeLevel'] as $grade) { //Set the elements in the array
$GradeLevel7 = $grade[0];
$GradeLevel8 = $grade[1];
$GradeLevel9 = $grade[2];
$GradeLevel10 = $grade[3];
$GradeLevel11 = $grade[4];
$GrageLevel12 = $grade[5];
}
}
This works, but allows you to select more than one radio button.
If I change the name to name="GradeLevel[]" then it stores the selected buttons value in the first field in the database (ie you select 'Grade 12' it stores that value in field 'Grade 7').
Is my explaination clear?
Am I way off base here?
Thanks in advance,
Don