简体   繁体   English

CodeIgniter:表单验证和显示错误

[英]CodeIgniter: Form Validation and displaying errors

I'm passing my validation errors to the next redirect using set_flashdata , however when I use this method I loose the data the user has inputted in the form. 我正在使用set_flashdata将验证错误传递给下一个重定向,但是当我使用此方法时,会丢失用户以表格形式输入的数据。 Is my approach incorrect here? 我的方法在这里不正确吗?

if($this->form_validation->run() == FALSE) {
    $this->session->set_flashdata('errors', validation_errors());        
    redirect($this->input->post('redirect'));
}
else {
    // do stuff
}

Dosc says this . DOSC说这个 Or in example: 或例如:

<?php defined('BASEPATH') OR exit('Not your cup of tea.');

class Auth extends CI_Controller
{
    public function login()
    {
        if($this->form_validation->run() == FALSE)
        {
            //$this->session->set_flashdata('errors', validation_errors()); #errors will be available without flashdata as well       
            //redirect($this->input->post('redirect')); #just load view again
            $this->load->view('view_where_form_with_action_auth_login_is')
        }
        else
        {
            // do stuff
            redirect('whereever', 'location')
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM