【问题标题】:Getting blank value for radio button获取单选按钮的空白值
【发布时间】:2017-08-08 18:56:09
【问题描述】:

试图通过 Post 接收在我的 PHP 中检查了哪个单选按钮,但由于某种原因,我没有得到任何价值。有没有人看到我哪里出错了?表单在经过一些验证后通过 javascript 提交。如果需要,我可以提供该代码。

按钮组 HTML:

<!-- Start Purchase Radio -->
    <div class="form-group">
        <div class="radio">
            <label>
                <input type="radio" name="transType" id="transTypePurchase" value="purchase">
                Purchase
            </label>
        </div>
    </div>
<!-- End Purchase Radio -->

<!-- Start Refinance Radio -->
    <div class="form-group">
        <div class="radio">
            <label>
                <input type="radio" name="transType" id="transTypeRefinance" value="refinance">
                Refinance
            </label>
        </div>
    </div>
<!-- End Refinance Radio -->

<!-- Start Transfer Radio -->
    <div class="form-group">
        <div class="radio">
            <label>
                <input type="radio" name="transType" id="transTypeTransfer" value="transfer">
                Transfer
            </label>
        </div>
    </div>
<!-- End Transfer Radio -->

<!-- Start Other Radio -->
    <div class="form-group">
        <div class="input-group">
            <span class="input-group-addon">
                <input type="radio" aria-label="Radio button for following text input" name="transType" id="transTypeOther">
            </span>
            <input type="text" class="form-control" aria-label="Text input with radio button" name="transType" id="transcationOtherText" onfocus="otherTextBox(transcationOtherText);" placeholder="Other">
        </div>
    </div>
<!-- End Other Radio -->

PHP:

if(isset($_POST['transType'])) {
    $value = $_POST['transType'];
    echo "*" . $value . "*";
}

【问题讨论】:

  • 你的同名文本输入的内容是什么?我相信它将始终使用输入框的内容,因为它是页面上具有该名称的最后一个元素
  • print_r($_POST); 是否包含其他预期的键/值?
  • 感谢大家的快速回复!答案如下。这是我的“其他”文本字段的名称与收音机相同。一旦我改变了它,我就得到了 radio 值。

标签: php html


【解决方案1】:

您与文本输入的无线电输入具有相同的名称。见

 <input type="text" class="form-control" aria-label="Text input with radio button" name="transType" id="transcationOtherText" onfocus="otherTextBox(transcationOtherText);" placeholder="Other">

更改上述输入的名称。

【讨论】:

  • 就是这样...花了 2 个小时试图弄清楚这一点。计时器到时会将其标记为正确答案。谢谢。
猜你喜欢
  • 2014-12-05
  • 1970-01-01
  • 2017-02-06
  • 2012-07-18
  • 2016-08-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多