PHP - 从提交中获取多个单选按钮值

时间:2016-04-20 09:34:58

标签: php

我是PHP的新手。我的表格如下:

<div class="col-xs-2 col-xs-offset-1">
    <input id="radio-ge-1" class="radio-custom" name="radio-ge" type="radio" value="1" checked>
    <label for="radio-ge-1" class="radio-custom-label tooltips">1 <span>Impossible to get marks</span></label>
</div>
<div class="col-xs-2">
    <input id="radio-ge-2" class="radio-custom" name="radio-ge" value="2" type="radio">
    <label for="radio-ge-2" class="radio-custom-label tooltips">2 <span>You have to work hard to get marks</span></label>
</div>
<div class="col-xs-2">
    <input id="radio-ge-3" class="radio-custom" name="radio-ge" value="3" type="radio">
    <label for="radio-ge-3" class="radio-custom-label tooltips">3 <span>The usual, just like any other class</span></label>
</div>


<div class="col-xs-2 col-xs-offset-1">
    <input id="radio-sl-1" class="radio-custom" name="radio-sl" value="1" type="radio" checked>
    <label for="radio-sl-1" class="radio-custom-label tooltips">1 <span>Unbearable pressure</span></label>
</div>
<div class="col-xs-2">
    <input id="radio-sl-2" class="radio-custom" name="radio-sl" value="2" type="radio">
    <label for="radio-sl-2" class="radio-custom-label tooltips">2 <span>High pressure, But doable</span></label>
</div>
<div class="col-xs-2">
    <input id="radio-sl-3" class="radio-custom" name="radio-sl" value="3" type="radio">
    <label for="radio-sl-3" class="radio-custom-label tooltips">3 <span>Fair, just like any other class</span></label>
</div>

我尝试使用以下代码保存PHP中的单选按钮值:

$g_Easiness = $_POST['radio-ge'];
$s_Load = $_POST['radio-sl'];

但在这种情况下,我只获得了第一个按钮的价值。第二个按钮的值=开。

我花了两个多小时来搞清楚。但无法解决它。有人可以帮我解决问题吗?

1 个答案:

答案 0 :(得分:1)

请使用以下代码用于单选按钮 如果输入类型=&#34; radio&#34;那么它应该给出值=&#34;&#34;否则它将显示&#34; on&#34; 例如

<input id="radio-must" class="radio-custom" name="radio-nns" value="absolutely" type="radio" checked>

output = [radio-nns] => on

代替put(你可以看到value =&#34; 1&#34;)

<input id="radio-must" class="radio-custom" name="radio-nns" value="absolutely" type="radio" checked value="1">

output =  [radio-nns] =>1