假设我有用户生成的数据,这些数据不是通过表单发布的。
有没有办法可以使用/扩展 CodeIgnitors form_validation 类来验证该数据。
eg.
<?php
$userData = array('name' => 'tt' , 'city' => 'London' , 'age' => '1200' );
// How can I validate this data using form_validation checks
// like min_length,max_length,and apply some processing
// like trim,xss_clean provided by the same class
?>
是的,您可以通过set_data()
方法,给你。
$this->form_validation->set_data(array(
'name' => 'Full Name',
'city' => 'City',
));
$this->form_validation->set_rules('name', 'Name', 'trim|required');
$this->form_validation->set_rules('city', 'City', 'trim|required');
$this->form_validation->set_rules('age', 'Age', 'trim|required');
if ($this->form_validation->run() == FALSE) {
echo 'Invalid: ' . validation_errors();
} else {
echo 'Valid';
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)