提交后保留下拉框选择 - PHP

时间:2014-11-18 13:10:10

标签: php radio retain

有没有办法在用户点击提交按钮后启用下拉框以保留其选择?目前它保留输入到文本框的信息,但是我无法将其应用于我的选择框和我的单选按钮。

这是我选择框的html代码:

<strong>Select Party Size* :</strong>
<select name="party" value="<?php echo $party;?>">
<option value="">Please Select</option>
<option value="5">1 Person (£5)</option>
<option value="10">2 People (£10)</option>
<option value="15">3 People (£15)</option>
<option value="20">4 People (£20)</option>
<option value="25">5 People (£25)</option>
<option value="30">6 People (£30)</option>
<option value="35">7 People (£35)</option>
<option value="40">8 People (£40)</option>
<option value="45">9 People (£45)</option>
<option value="50">10+ People (£50)</option>
</select>
<span id="partySize" class="error"><?php echo $partyErr;?></span>

这是选择框的php:

if($_POST['party']=="") {
    $partyErr = "Please select the party size";
} else {
    $party = test_input($_POST["party"]);
}

这里也是我的单选按钮,我想将其应用于:

HTML:

<strong> VIP area* : </strong> <br><br> Yes (+£5)  <input type="radio" name="vip" value="yes">
<?php if (isset($vip) && $vip=="yes");?>
<br><span id="vip" class="error"><?php echo $vipErr;?></span><br> 
No  <input type="radio" name="vip" value="no">
<?php if (isset($vip) && $vip=="no");?>

PHP:

if (empty($_POST["vip"])) {
    $vipErr = "Please make a VIP area selection";
} else {
    $vip = test_input($_POST["vip"]);
}

1 个答案:

答案 0 :(得分:0)

问题在于您的HTML。 select标记在相应的value元素上没有selected属性,you need to set option。同样radio buttons use属性checked="checked"