Welcome Guest, Not a member yet? Register   Sign In
Form Validation - Redirect
#1

[eluser]pointer[/eluser]
Hi, I can show validation errors on page with

Code:
if( $this->form_validation->run() == FALSE )
{
   $this->load->view('foo');
}


but when I use

Code:
if( $this->form_validation->run() == FALSE )
{
   redirect('foo/bar/', 'refresh');
}

I can't show error messages
any idea?
thanks.
#2

[eluser]darkhouse[/eluser]
Since it's a redirect, the form validation doesn't retain any data. You're going to a new page without posting anything so you've lost everything. What you might want to do in that case is use flashdata, like this:

Code:
if($this->form_validation->run() == FALSE)
{
   $this->session->set_flashdata('error', validation_errors());
   redirect('foo/bar/', 'refresh');
}

I also don't recommend using the 'refresh' option, simply because I've had a number of users end up with a blank page after a redirect with a 'refresh', while it worked for everyone else. Not entirely sure what the problem was, but I haven't had any issues by just doing redirect('foo/bar');




Theme © iAndrew 2016 - Forum software by © MyBB