[英]CodeIgniter Form Validation. Multiple calls not working
I am using CodeIgniter. 我正在使用CodeIgniter。 I have been trying to debug a non-working script. 我一直在尝试调试不起作用的脚本。
I have come to the conclusion that when utilizing $this->form_validation->run();
我得出的结论是,在使用$this->form_validation->run();
(the form validation class), after the first named call, eg $this->form_validation->run(form_1);
(表单验证类),在第一个命名调用之后,例如$this->form_validation->run(form_1);
, all following calls return true. ,以下所有调用均返回true。
I am developing a multi step form and when $this->form_validation->run(form_1);
我正在开发一个多步骤表单,当$this->form_validation->run(form_1);
correctly returns true, $this->form_validation->run(form_2);
正确返回true, $this->form_validation->run(form_2);
incorrectly returns true. 错误地返回true。
Anyone have any clue as to why? 有人对为什么有任何线索吗? Can multiple calls not be held in a single function within a controller or is there a special approach? 控制器中的单个功能中是否不能保留多个调用?是否有特殊方法? Cheers 干杯
the way codeigniter is setup doesn't lend itself to allow you to validate with multiple rules, you can extend the form helper with a function to group rules ( http://ellislab.com/codeigniter/forums/viewthread/120221 ) or like I did in my application/config/form_validation.php
I simply combined multiple groups into its own set of rules and referred to the single rule of combined rules. 设置codeigniter的方式本身不适合您使用多个规则进行验证,您可以使用功能对表单助手进行扩展以对规则进行分组( http://ellislab.com/codeigniter/forums/viewthread/120221 )或类似的功能我在application/config/form_validation.php
我只是将多个组组合成自己的规则集,并引用了组合规则的单个规则。
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$config = array(
"campaign" => array(
array(
"field" => "campaign[title]",
"label" => "campaign title",
"rules" => "trim|required|max_length[255]|xss_clean"
)
),
"user" => array(
array(
"field" => "user_info[email]",
"label" => "email",
"rules" => "trim|required|valid_email|is_unique[user_info.email]|max_length[255]|xss_clean"
)
)
);
$config["campaign_user"] = array_merge($config['campaign'], $config['user']);
The line of interest is the last one, where the two rules are combined: 兴趣线是最后一条,将两个规则组合在一起:
$config["campaign_user"] = array_merge($config['campaign'], $config['user']);
and in your controller you would just call the single rule: 在您的控制器中,您只需调用一条规则:
if($this->form_validation->run('campaign_user'))
{
# validation successful
}
请检查您的set_rules()函数中是否具有传递参数(form1)和(form2).....如果可以,请使自己的第一个form_validation调用返回FALSE,然后查看对form_validation的第二个调用是否仍返回TRUE 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.