如何将注册表单重定向到codeigniter上的另一个页面

时间:2017-04-05 01:04:27

标签: php forms codeigniter

当用户提交注册表单时,如何重定向到成功页面,问题是当我提交表单时,它将重定向到成功视图,但页面显示404未找到。我的代码中有什么问题吗?

公共职能登记(){

    $this->load->library('form_validation');

    $this->form_validation->set_rules('fname','First Name','required');
    $this->form_validation->set_rules('lname','Last Name','required');
    $this->form_validation->set_rules('username','username','required');
    $this->form_validation->set_rules('password','Password','required');
    $this->form_validation->set_rules('cpassword','Confim Password','required|matches[password]');

    if ($this->form_validation->run()  ) {

        $this->load->model('Registration');

        $this->Registration->create(
            ['fname' => ucfirst($_POST['fname']),
             'lname' => ucfirst($_POST['lname']), 
             'username' => ucfirst($_POST['username']),
             'password' => md5($_POST['password'])]);   

        redirect('templates/rsuccess');

    } else {
    $view_data['page_title'] = 'Register first';
    $view_data['errors'] = $this->form_validation->error_array();

    $this->load->view('templates/header', $view_data);
    $this->load->view('auth/registration');
    $this->load->view('templates/footer');

    }
}

3 个答案:

答案 0 :(得分:1)

请检查我的更改

$this->load->library('form_validation');

$this->form_validation->set_rules('fname','First Name','required');
$this->form_validation->set_rules('lname','Last Name','required');
$this->form_validation->set_rules('username','username','required');
$this->form_validation->set_rules('password','Password','required');
$this->form_validation->set_rules('cpassword','Confim Password','required|matches[password]');

if ($this->form_validation->run()  ) {

    $this->load->model('Registration');

    $this->Registration->create(
        ['fname' => ucfirst($_POST['fname']),
         'lname' => ucfirst($_POST['lname']), 
         'username' => ucfirst($_POST['username']),
         'password' => md5($_POST['password'])]);   

    redirect(base_url().'templates/rsuccess', 'location', 301);


} else {
$view_data['page_title'] = 'Register first';
$view_data['errors'] = $this->form_validation->error_array();

$this->load->view('templates/header', $view_data);
$this->load->view('auth/registration');
$this->load->view('templates/footer');

}
}

答案 1 :(得分:0)

使用此

 redirect('controller/function');

答案 2 :(得分:0)

使用100*sqrt(5)

redirect()