我的网站上有大型表格,所有这些都需要在提交时进行验证。由于我在codeigniter工作,我通常手动为每个输入设置表单验证规则,如下所示:
$validation_rules = array (
array ( 'field' => 'name', 'label' => 'Full name', 'rules' => 'required' ),
array ( 'field' => 'telephone', 'label' => 'Contact Number', 'rules' => 'required' ),
---
---
---
);
看起来循环可以解决第一个问题吗?
foreach ( $this->input->post ( ) as $key => $value )
{
if ( strcasecmp ( $key, 'email' ) === 0 )
{
$this->form_validation->set_rules ( $key, ucfirst ( $key ), 'required|valid_email|trim' );
}
else
{
$this->form_validation->set_rules($key, ucfirst($key), 'required|trim');
}
}