English 中文(简体)
准则
原标题:CodeIgniter Set Form Validation Redirect URL

当由于一些田地缺失而出现单价时,有效制片人会因违约而向现任控制员/方法重新方向。 这意味着,如果我为签署这条通往修缮/登记的道路铺设一条路,我就希望它回到这条路上,而不是实际上的控制人的道路。

任何建议?

function register() {
        $this->load->library( form_validation );     
        $this->form_validation->set_rules( name ,  Name ,  required|xss_clean );
        $this->form_validation->set_rules( description ,  Description ,  required|xss_clean );
        $this->form_validation->set_rules( contact ,  Contact ,  required|xss_clean );
        $this->form_validation->set_rules( email ,  Email Address ,  required|valid_email );
        $this->form_validation->set_rules( password ,  Password ,  required|min_length[  . $this->config->item( min_password_length ,  ion_auth ) .  ]|max_length[  . $this->config->item( max_password_length ,  ion_auth ) .  ]|matches[password_confirm] );
        $this->form_validation->set_rules( password_confirm ,  Password Confirmation ,  required );

        if ($this->form_validation->run() == true) {
                // Do some stuff here
        } else {

            $data[ message ] = (validation_errors() ? validation_errors() : ($this->ion_auth->errors() ? $this->ion_auth->errors() : $this->session->flashdata( message )));

            $data[ name ] = array( name  =>  name ,
                 id  =>  name ,
                 type  =>  text ,
                 value  => $this->form_validation->set_value( name ),
            );
            $data[ description ] = array( name  =>  description ,
                 id  =>  description ,
                 type  =>  textarea ,
                 value  => $this->form_validation->set_value( description ),
                 class  =>  form-textarea ,
            );
            $data[ email ] = array( name  =>  email ,
                 id  =>  email ,
                 type  =>  text ,
                 value  => $this->form_validation->set_value( email ),
            );

            $data[ contact ] = array( name  =>  contact ,
                 id  =>  contact ,
                 type  =>  text ,
                 value  => $this->form_validation->set_value( contact ),
            );

            $data[ password ] = array( name  =>  password ,
                 id  =>  password ,
                 type  =>  password ,
                 value  => $this->form_validation->set_value( password ),
            );
            $data[ password_confirm ] = array( name  =>  password_confirm ,
                 id  =>  password_confirm ,
                 type  =>  password ,
                 value  => $this->form_validation->set_value( password_confirm ),
            );

            $this->load->view( organisations/create , $data);
        }
    }
问题回答

I would set the default behavior to what you want if the form is not submitted or if there are validation errors and then redirect if the user if the form is successfully processed.

i.e.

function register() {
    $this->load->library( form_validation );     
    $this->form_validation->set_rules( name ,  Name ,  required|xss_clean );
    $this->form_validation->set_rules( description ,  Description ,  required|xss_clean );
    $this->form_validation->set_rules( contact ,  Contact ,  required|xss_clean );
    $this->form_validation->set_rules( email ,  Email Address ,  required|valid_email );
    $this->form_validation->set_rules( password ,  Password ,  required|min_length[  . $this->config->item( min_password_length ,  ion_auth ) .  ]|max_length[  . $this->config->item( max_password_length ,  ion_auth ) .  ]|matches[password_confirm] );
    $this->form_validation->set_rules( password_confirm ,  Password Confirmation ,  required );

    if ($this->form_validation->run()) {
        // Do some stuff here to process the form
        // Maybe set the success flash message
        // Then redirect
        redirect( organizations/login );
    } else {

        $data[ message ] = (validation_errors() ? validation_errors() : ($this->ion_auth->errors() ? $this->ion_auth->errors() : $this->session->flashdata( message )));

        $data[ name ] = array( name  =>  name ,
             id  =>  name ,
             type  =>  text ,
             value  => $this->form_validation->set_value( name ),
        );
        $data[ description ] = array( name  =>  description ,
             id  =>  description ,
             type  =>  textarea ,
             value  => $this->form_validation->set_value( description ),
             class  =>  form-textarea ,
        );
        $data[ email ] = array( name  =>  email ,
             id  =>  email ,
             type  =>  text ,
             value  => $this->form_validation->set_value( email ),
        );

        $data[ contact ] = array( name  =>  contact ,
             id  =>  contact ,
             type  =>  text ,
             value  => $this->form_validation->set_value( contact ),
        );

        $data[ password ] = array( name  =>  password ,
             id  =>  password ,
             type  =>  password ,
             value  => $this->form_validation->set_value( password ),
        );
        $data[ password_confirm ] = array( name  =>  password_confirm ,
             id  =>  password_confirm ,
             type  =>  password ,
             value  => $this->form_validation->set_value( password_confirm ),
        );
    }

    $this->load->view( organisations/create , $data);
}

这可能要求你改变现在如何安排某些事情,但我发现这是处理这种情况的最容易的方法。





相关问题
PHP Framework: Ebay Like Site

I am going to be builiding a site like ebay - with all the features of ebay. Please note my payment method is limited to paypal. What would be the best PHP framework to use to build this quickly, ...

What s the proper MVC way to do this....?

Quick question about general MVC design principle in PHP, using CodeIgniter or Kohana (I m actually using Kohana). I m new to MVC and don t want to get this wrong... so I m wondering if i have ...

Check session from a view in CodeIgniter

What is the best way to check session from a view in CodeIgniter, it shows no way in their user guide, otherwise I will have to make two views on everything, which is kinda weird...still a newbie to ...

Using SimplePie with CodeIgniter and XAMPP

I am using CodeIgniter 1.7.2 with XAMPP 1.7.2 on a Windows computer. I am trying to make use of SimplePie. I followed all the instructions I could find: a copy of simplepie.inc is in my applications/...

CodeIgniter adding semicolons

How do I stop CodeIgniter adding semicolons ; to data sent via POST that contains ampersand &? For example it is converting "a=1&b=2&c=3" into "a=1&b;=2&c;=3". From looking on the forums ...

Best way to make Admin pages in CodeIgniter?

I m working on an app in CodeIgniter, and I want to have admin pages for several of the objects in the application, and I m wondering what would be the better way to put these into an MVC structure. ...

CodeIgniter form verification and class

I m using the form validation library and have something like this in the view <p> <label for="NAME">Name <span class="required">*</span></label> <?...

热门标签