A question about the CI framework

Source: Internet
Author: User
For example, a login method is used to output the login view {code...}. At this time, the login page is indexlogin. Then, submit the form data to the login_check () method {code ...} $ this-& amp; gt; form_validation-& amp; gt; run () Form Verification Failed, output again l... for example, a login method is used to output the login view.
public function login(){    $this->load->view('login');}
At this time, the login page is index/login. Then, submit the form data login_check()Method
public function login_check(){    $this->form_validation->set_rules('email', 'email', 'trim|required|valid_email');    $this->form_validation->set_rules('password', 'password', 'trim|required');    if ($this->form_validation->run() === true) {        //.....    }else{        $this->load->view('login');    }}
$this->form_validation->run()Form Verification Failed. the login view is output again and an error is displayed. At this time, the login page address index/login_check. This is so bad that you do not want the link address to change. In addition login()And login_check()In addition to the implementation of merge processing, is there any better solution? Thank you for your advice.

Reply content: for example, a login method is used to output the login view.
public function login(){    $this->load->view('login');}
At this time, the login page is index/login. Then, submit the form data login_check()Method
public function login_check(){    $this->form_validation->set_rules('email', 'email', 'trim|required|valid_email');    $this->form_validation->set_rules('password', 'password', 'trim|required');    if ($this->form_validation->run() === true) {        //.....    }else{        $this->load->view('login');    }}
$this->form_validation->run()Form Verification Failed. the login view is output again and an error is displayed. At this time, the login page address index/login_check. This is so bad that you do not want the link address to change. In addition login()And login_check()In addition to the implementation of merge processing, is there any better solution? Thank you for your advice.

You can submit the form using ajax. This will not cause the page to jump to login_check.

Jump to if verification failslogin?error=err_code

Use in CIredirect('index/login')This function is redirected.

In yourelseUsed in

To solve this problem elegantly, you need to use routes,
JudgmenthttpIng the verb to the corresponding method.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.