在验证失败时重新填充单选按钮 [英] Repopulate radio buttons on failed validation

查看:93
本文介绍了在验证失败时重新填充单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从数据库中提取数据的表单。
如果是输入框,代码可以正常工作,但是无法获得单选按钮的最新$ _POST数据。

I have a form that pulls data from a database. Code works fine if it’s an input box but I can’t get the latest $_POST data for radio buttons.

这适用于输入文本框。我在第一次加载时获取从数据库中提取的默认值,并且我可以从用户那里获得用户修改输入框的新输入(如果有)。验证失败。

This works for input text box. I get default values pulled from the DB on first load, and I can get the new input (if any) from the user modifies the input box on a failed validation.

<?php echo form_input('email',set_value('email', $email)); ?>

这是我的一个单选按钮的代码。它在我从数据库中提取数据时工作,但如果表单因为验证失败而刷新,我不知道如何显示用户选择的内容。

Here’s the code for one of my radio button. It works when I’m pulling data from the DB, but if the form refreshes due to a failed validation, I’m not sure how I can show what the user selected.

<input type="radio" name="gender" value="male" <?php if($gender == "male") echo "checked";  ?> />Male

我玩过set_radio,但我遇到了同样的问题。这在初始加载,但是对于失败的验证怎么办?我尝试在第二个参数中抛出set_radio,但是没有工作。

I played around with set_radio but i ran into the same issue. This works on initial load, but what about on a failed validation? I tried throwing "set_radio" in the second paramter but that didn't work either.

if($gender == "male") {
    echo form_radio('gender', 'male',TRUE)
} else {
   echo form_radio('gender', 'male')
}


推荐答案

看起来像我可以使用相同的代码一个文本框。

Looks like I was able to use the same code as I would for a text box.

这篇关于在验证失败时重新填充单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆