Log in

View Full Version : radio buttons and hidden fields



sgilleland
10-17-2008, 05:56 PM
I want to be able to use radio buttons on my form but I need the selected one to update 2 seperate fields in my database. I am attaching what I have tried, but didn't work. I am new to all of this, so please be gentle
HTML Code:

<INPUT class="element radio" id=element_5_1 type=radio value=Swee****er Golf and CC=Ub2venue> <input type="hidden" name="Ub2bwsdate" value="10/22/2008"/>
<LABEL class=choice for=element_5_1>Oct. 22 6:30p.m. Swee****er Golf and Country Club, Apopka </LABEL>
<INPUT class="element radio" id=element_5_2 type=radio value=Swee****er Golf and CC=Ub2venue> <input type="hidden" name="Ub2bwsdate" value="10/23/2008"/>
<LABEL class=choice for=element_5_2>Oct. 23 2:30p.m. Swee****er Golf and County Club, Apopka </LABEL>
<INPUT class="element radio" id=element_5_3 type=radio value=USBank, KC=Ub2venue> <input type="hidden" name="Ub2bwsdate" value="10/28/2008"/>
<LABEL class=choice for=element_5_3>Oct. 28 2:30 p.m. USBank, Kansas City </LABEL>
<LABEL class=choice for=element_5_4></LABEL> </SPAN>


I need it to update field Ub2venue with the locaion and update the Ub2bwsdate field with the date from the selected one.

Any help would be appreciated.

Jesdisciple
10-20-2008, 11:48 PM
HTML requires that you quote any attribute values which contain spaces, and it's a good idea to quote all of them.

Radio buttons and hidden fields cannot be associated in any way (without JavaScript), but you can use one HTML field to update two database fields.

Finally, PHP can handle arrays in forms.
<INPUT class="element radio" id="element[5][1]" type="radio" value="Swee****er Golf and CC=Ub2venue|10/22/2008">
<LABEL class="choice" for="element[5][1]">Oct. 22 6:30p.m. Swee****er Golf and Country Club, Apopka </LABEL>
<INPUT class="element radio" id="element[5][2]" type="radio" value="Swee****er Golf and CC=Ub2venue|10/23/2008">
<LABEL class="choice" for="element[5][2]">Oct. 23 2:30p.m. Swee****er Golf and County Club, Apopka </LABEL>
<INPUT class="element radio" id="element[5][3]" type="radio" value="USBank, KC=Ub2venue|10/28/2008">
<LABEL class="choice" for="element[5][3]">Oct. 28 2:30 p.m. USBank, Kansas City </LABEL>

In your PHP...
$element = $_POST['element'];
for($i = 1; $i <= count($element[5]); $i++){
$element[5][$i] = explode('|', $_POST['element'][5][$i]);
$location = $element[5][$i][0];
$date = $element[5][$i][1];
}