2010-03-07 37 views
0

我的情況有點複雜。我想創建$配置規則,我form_validation使我的代碼更乾淨,但問題就在這裏:如何在CodeIgniter中添加config_d Form_validation?

 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'); 
     } 

我該怎麼辦,如果我有有條件的規則?

回答

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 
    } 
} 

這會奏效。

相關問題