提交后保持收音机检查

时间:2018-04-30 10:36:15

标签: php submit radio

如何在用户提交表单后检查收音机? 提交后,用户将保持在同一页面上。除了AJAX之外还有其他方式吗?我不熟悉AJAX,更喜欢PHP。

<form action="submit.php" method="POST">
<div id="radioboomboomboom">
<input type="radio" name="branch"  value="[KL]" required> KL <br>
<input type="radio" name="branch"  value="[JB]"  required> JB <br>
<input type="radio" name="branch"  value="[PG]"  required> Penang <br>
<input type="radio" name="branch"  value="[MLK]"  required> Melacca</div> 
<br>
<input type="submit" name= "submit" id="submit" value="Submit"/>
</form>

1 个答案:

答案 0 :(得分:1)

您需要检查POST数据,并根据相应的单选按钮添加checked属性。

这样做: -

<form action="submit.php" method="POST">
    <div id="radioboomboomboom">
        <input type="radio" name="branch"  value="[KL]" <?php if(isset($_POST['branch']) && $_POST['branch'] =='[KL]' ){echo "checked";}?> required> KL <br>
        <input type="radio" name="branch"  value="[JB]"  <?php if(isset($_POST['branch']) && $_POST['branch'] =='[JB]' ){echo "checked";}?> required> JB <br>
        <input type="radio" name="branch"  value="[PG]"  <?php if(isset($_POST['branch']) && $_POST['branch'] =='[PG]' ){echo "checked";}?> required> Penang <br>
        <input type="radio" name="branch"  value="[MLK]"  <?php if(isset($_POST['branch']) && $_POST['branch'] =='[MLK]' ){echo "checked";}?> required> Melacca
    </div> 
    <br>
    <input type="submit" name= "submit" id="submit" value="Submit"/>
</form>