You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

HTML表单单选按钮提交值异常:发送"on"而非预期选中值

问题原因与解决方法

你的单选按钮没有设置value属性,这就是后端PHP拿到的值是"on"而非预期值的核心原因。

HTML规范里,单选框(radio)如果不指定value属性,浏览器会默认使用字符串"on"作为提交值。你需要给每个单选按钮添加value,明确指定提交时对应的值,修改后的代码如下:

<form action="admin_review.php?opt=newReview" method="post" >
    <fieldset>
        <legend>Review Type</legend>
        <div class="input">
            <label for="movie">Movie Review</label>
            <input type="radio" name="reviewType" id="movie" value="movie">
        </div>
        <div class="input">
            <label for="television">Television Review</label>
            <input type="radio" name="reviewType" id="television" value="television">
        </div>
        <div class="input">
            <label for="book">Book Review</label>
            <input type="radio" name="reviewType" id="book" value="book">
        </div>
        <div class="input">
            <label for="comic">Comic Review</label>
            <input type="radio" name="reviewType" id="comic" value="comic">
        </div>
        <div class="input">
            <label for="game">Game Review</label>
            <input type="radio" name="reviewType" id="game" value="game">
        </div>
    </fieldset>
    <input type="submit" value="New Review Defintion"> 
</form>

修改后,当用户选中某个选项,后端$_POST['reviewType']就能拿到对应的value值(比如选中Movie Review时拿到"movie")。

另外补充:你当前的label和input关联是正确的(for属性对应input的id),这部分没问题,不影响提交值的问题。

内容的提问来源于stack exchange,提问作者ScaryMinds

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 13:52:14