我的情况有点复杂。我想为我的form_validation创建$ config规则,以便我的代码更清晰,但问题在于:
if( $this->input->post( 'usertype' ) == "new_user" )
{
$this->form_validation->set_rules('new_email', 'E-mail Address', 'required|valid_email' );
$this->form_validation->set_rules('new_firstname', 'First Name', 'required' );
$this->form_validation->set_rules('new_lastname', 'Last Name', 'required' );
$this->form_validation->set_rules('new_password', 'Password', 'required|matches[password_conf]' );
$this->form_validation->set_rules('password_conf', 'Password Confirmation', 'required' );
} else {
$this->form_validation->set_rules('login_email', 'Login E-mail Address', 'required|valid_email' );
$this->form_validation->set_rules('login_password', 'Login Password Address', 'required' );
}
如果我有条件规则怎么办?
答案 0 :(得分:1)
if( $this->input->post( 'usertype' ) == "new_user" )
{
if ($this->form_validation->run('booking_create_new_account') == TRUE)
{
// do stuff
}
}
else
{
if ($this->form_validation->run('booking_create') == TRUE)
{
// do stuff
}
}
这样可行。