【发布时间】:2020-06-24 09:01:11
【问题描述】:
我正在尝试使用 codeigniter 中的 set_rules 函数对变量值进行验证。有可能吗?
我的代码如下:
$client_name = "Some name";
$this->form_validation->set_rules($client_name,'Client','required');
即使我尝试直接在 Post 变量中设置值,如下所示:
$a = array('Name1','','Name3');
foreach($a as $client_name ) {
$_POST['client_name'] = $client_name = "Some name";
echo "--- " . validation_errors();
$this->form_validation->set_rules('client_name','Client','required');
if (!$this->form_validation->run())
{
echo validation_errors();
}
else
{
echo 'validation successful';
}
}
此代码给出以下输出:
--- // No validation error
validation successful //first time validation successfully ran
--- // No validation error
Client field is required //first time validation failed
--Client field is required // validation error from the second loop
Client field is required
如果可能,请提供帮助。
提前致谢。
【问题讨论】:
标签: php codeigniter validation codeigniter-2