我在一个页面中有 2 个表单,它们是注册和登录表单,我为每个表单定义了一个名称,以便我可以单独发布它,但我怎么能只写 1 个 form_validation-run() ?
public function index()
{
//load form_validation and session library
$this->load->library(array('form_validation','session'));
if ( $this->input->post('register') ) {
$this->form_validation->set_rules('first_name', 'First name', 'required');
$this->form_validation->set_rules('last_name', 'Last name', 'required');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email');
$this->form_validation->set_rules('password', 'Password', 'required|min_length[6]');
if ( $this->form_validation->run() !== FALSE ){
// to create an account
} else {
$this->session->set_flashdata('msg', validation_errors('<div>','</div>'));
redirect('/','location');
}
} elseif ( $this->input->post('login')) {
$this->form_validation->set_rules('email', 'Email', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
if ( $this->form_validation->run() !== FALSE ) {
// to get login
} else {
$this->session->set_flashdata('msg', validation_errors('<div>','</div>'));
redirect('/','location');
}
}
$this->load->view('templates/header');
$this->load->view('pages/index');
$this->load->view('templates/footer');
}