为什么`set_radio`不工作,当“form_validation”包括? [英] Why `set_radio` doesn't work when "form_validation" is included?

查看:104
本文介绍了为什么`set_radio`不工作,当“form_validation”包括?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在呼叫视图

function index() {
    $this->load->helper("form");
    $this->load->library("form_validation");

    $this->load->view("index");
}

然后我有

<?php echo form_open(); ?>

<input type="radio" name="radioname" value="x" <?php echo set_radio("radioname", "x", true); ?> />
<input type="radio" name="radioname" value="y" <?php echo set_radio("radioname", "y"); ?> />

</form>

在第一次加载时,如果我发布表单的值成功到 $ this-> input-> post()。但没有一个收音机盒子被检查。如果我不加载验证代码工作。

At the first load I get the first radio checked. If I post the form the value goes successfully to $this->input->post(). But none of the radio boxes get checked. If I don't load the validation the code works.

我挖出代码,发现如果 form_validation

I dug the code and found that if the form_validation is loaded it behaves differently.

$OBJ =& _get_validation_object();

if ($OBJ === FALSE)
{
    // returns formhelper set_radio
}

// this doesn't make sense for me
return $OBJ->set_radio($field, $value, $default);

如果加载了 form_validation set_radio $ OBJ ,但不起作用。

If the form_validation is loaded it executes the set_radio from $OBJ, but it doesn't work.

在这种情况下, $ OBJ 究竟是什么?

What exactly is $OBJ in this context? What do I have to change to make it work?

推荐答案

您需要向radioname添加假规则,例如

You need to add fake rule to radioname like

$this->form_validation->set_rules("radioname", "", "trim");

这篇关于为什么`set_radio`不工作,当“form_validation”包括?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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