T. *_*nes 8 forms validation post codeigniter get
我有一个完美的表单,直到我将表单切换到method="get".现在我无法form_validation->run()评估为TRUE.
这是我打开表单的方式:
echo form_open( '', array( 'method' => 'get' ) );
这是唯一需要验证的部分:
$this->form_validation->set_rules( 'states', 'states', 'required' );
这是我检查表单是否经过验证的方式:
if( $this->form_validation->run() == FALSE )
使用Get参数我还需要做些什么吗?我在config($config['allow_get_array'] = TRUE;)中打开了参数.如果我跳过验证,表单工作正常,所以我知道CI系统正在读取网址.
gX.*_*gX. 13
对于CodeIgniter 3,您可以将GET数组传递给set_data函数.例如:
$this->form_validation->set_data($this->input->get());
小智 6
只需添加:
$_POST['states'] = $this->input->get('states');
用于在表单验证之前验证状态字段
$this->form_validation->set_rules('states', 'states', 'required|trim');