如何设置CodeIgniter单选按钮,它在$ _POST之前? [英] How do you set a CodeIgniter radio button, before it's in the $_POST?

查看:125
本文介绍了如何设置CodeIgniter单选按钮,它在$ _POST之前?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,在CodeIgniter表单助手中( http://ellislab.com/ codeigniter / user-guide / helpers / form_helper.html )您有此功能:



set_radio()



允许您以提交的状态显示单选按钮。
此函数与上述set_checkbox()函数相同。

 < input type =radioname = myradiovalue =1<?php echo set_radio('myradio','1',TRUE); ?> /> 
< input type =radioname =myradiovalue =2<?php echo set_radio('myradio','2'); ?> />

问题是我在提交表单之前已经有信息。据我理解,这个 set_radio()函数使用POST操作中的数据在表单验证失败时设置值,需要重做。



这是否有意义?



所以如果我还没有做第一个POST, c $ c> set_radio()没有任何数据用于预设单选按钮。

解决方案

您可以随时修改 $ _ POST 变量, / p>

  if(!isset($ _ POST ['myradio'])){
$ _POST ['myradio'] = $ myDefaultValue;
}

在开始使用表单助手之前执行此操作, / p>

So in the CodeIgniter form helper, (http://ellislab.com/codeigniter/user-guide/helpers/form_helper.html) you have this function:

set_radio()

Permits you to display radio buttons in the state they were submitted. This function is identical to the set_checkbox() function above.

<input type="radio" name="myradio" value="1" <?php echo set_radio('myradio', '1', TRUE); ?> />
<input type="radio" name="myradio" value="2" <?php echo set_radio('myradio', '2'); ?> />

The problem is that I already have information BEFORE I present the form. As I understand it, this set_radio() function uses the data in the POST action to set the value when the form validation fails, and needs to be redone.

Does that make sense?

So if I haven't done the first POST yet, the set_radio() doesn't have any data to use to pre-set the radio button.

解决方案

You can always modify $_POST variable, like this:

if (!isset($_POST['myradio'])) {
    $_POST['myradio'] = $myDefaultValue;
} 

Do this before you start working with form helper and you should be fine.

这篇关于如何设置CodeIgniter单选按钮,它在$ _POST之前?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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