【问题标题】:Get the value from radio button and pass it to controller (using PHP codeIgniter)从单选按钮获取值并将其传递给控制器​​(使用 PHP codeIgniter)
【发布时间】:2019-02-05 06:41:48
【问题描述】:

这是供用户填写的表格:

<form action="/process" method="post>
    <div class="donationarea">
                <strong>I would like to adopt:*</strong>
                <fieldset class="form-group">
                    <div class="form-check">
                       <input class="form-check-input" type="radio" name="squaremeter" value="1"> 
                       <label class="form-check-label">
                           1 m2 (€ 2,50)
                       </label>
                    </div>
                    <div class="form-check">
                       <input class="form-check-input" type="radio" name="squaremeter" value="4">
                       <label class="form-check-label">
                           4 m2 (€ 10,-)
                       </label>
                    </div>
                    <div class="form-check">
                       <input class="form-check-input" type="radio" name="squaremeter" value="10">
                       <label class="form-check-label">
                           10 m2 (€ 25,-)
                       </label>
                    </div>
                    <div class="form-check">
                       <input class="form-check-input" type="radio" name="squaremeter" value="20">
                       <label class="form-check-label">
                           20 m2 (€ 50,-)
                       </label>
                    </div>
                    <div class="form-check">
                       <input class="form-check-input" type="radio" name="squaremeter" value="other">
                       <label class="form-check-label">
                          Otherwise, namely (m2): <input type="text" name="squaremeter" placeholder="m2">
                       </label>
                    </div> 
                </fieldset>

            </div> 
</form>

点击提交按钮后,表单返回的数据如下:

除了第一个返回空字符串的单选按钮外,我们获取所需输入字段的每个帖子数据。有什么提示吗?

【问题讨论】:

  • 这些html代码是放在表单里面还是表单外面?因为我在这里看不到任何表单?
  • 或者控制器内部的验证规则可能有些奇怪,请显示控制器的验证部分。
  • 这段代码的用途。否则,即 (m2): 缺少 value 参数,可能正在测试您正在选择它。

标签: php forms codeigniter


【解决方案1】:

请选中一个单选按钮。 如果您没有选中任何单选按钮,则它在帖子中为空白。

也许对你有帮助。

【讨论】:

  • 我在发送表单之前已经选中了一个单选按钮。
【解决方案2】:

简单认为你需要改变你否则,即(m2)输入文本名称到name =“squaremeter-1”然后你会得到价值

Array
(
    [squaremeter] => other
    [squaremeter-1] => 
)

【讨论】:

    【解决方案3】:

    它是空的,因为你有一个与radibuttons同名的输入文本:squaremeter

    将输入文本重命名为squaremeter-other

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-22
      • 1970-01-01
      • 2021-11-17
      • 1970-01-01
      • 2019-07-06
      • 2017-11-30
      • 2019-03-24
      • 2014-03-26
      相关资源
      最近更新 更多