表单填充帮助器,使用URL变量从单选按钮中进行选择


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

我试图通过将变量传递到PHP中的URL来选择无线电组上的项目,但不知何故它不起作用。我试着用它来链接到表单:

链接到表单

<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>

表单页面和表单元素名称

<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>

你需要得到你在URL中传递的变量,然后根据它是什么检查一个单选按钮

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>