cloudrunner
cloudrunner

Reputation: 489

Form fillup helper, using a URL variable to select from a radio button

I'm trying to select an item on a radio group by passing a variable to the URL in PHP, but somehow its not working. I tried using it on a link to the form:

Link to the Form

<a class="button fright" href="reserve.php?rsrv_room=Standard" >Reserve Now</a>
<a class="button fright" href="reserve.php?rsrv_room=Family" >Reserve Now</a>
<a class="button fright" href="reserve.php?rsrv_room=Deluxe" >Reserve Now</a>

Form Page and form element name

<input name="rsrv_room" type="radio" id="rsrv_room_1" value="Standard" />Standard Room</label>
<label>
<input type="radio" name="rsrv_room" value="Family" id="rsrv_room_2" />Family Room</label>
<label>
<input type="radio" name="rsrv_room" value="Deluxe" id="rsrv_room_3" />Deluxe Room</label>

Help would really be appreciated.

Upvotes: 0

Views: 230

Answers (1)

a2345sooted
a2345sooted

Reputation: 599

You need to get the variable you passed in the URL and then check a radio button depending on what it is.

try this:

<label>
<input name="rsrv_room" type="radio" id="rsrv_room_1" value="Standard" 
 <?php if ($_GET['rsrv_room'] == 'Standard') { echo ' checked'; } ?>
/>Standard Room
</label>

<label>
<input type="radio" name="rsrv_room" value="Family" id="rsrv_room_2" 
 <?php if ($_GET['rsrv_room'] == 'Family') { echo ' checked'; } ?>
/>Family Room
</label>

<label>
<input type="radio" name="rsrv_room" value="Deluxe" id="rsrv_room_3" 
 <?php if ($_GET['rsrv_room'] == 'Deluxe') { echo ' checked'; } ?>
/>Deluxe Room
</label>

Upvotes: 1

Related Questions