Welcome Guest, Not a member yet? Register   Sign In
Form validation after a redirect
#1

[eluser]djmccormick[/eluser]
I'm wondering if anyone has any advice on the possibility of performing form validation then redirecting the user back to the form page if the form validation fails. Basically I'd like to maintain the state of the form validation after a redirect.

I realize I could just load a view within my processing function, but I'd like to do a redirect for two reasons: URL consistency and to prevent accidental double submissions. Any tips?

Thanks in advance!
#2

[eluser]Thorpe Obazee[/eluser]
When you submit it to it's current uri, it won't change the url unless you purposely redirect in the controller function.

To prevent accidental double submissions, you'd probably turn to sessions.
#3

[eluser]djmccormick[/eluser]
One reason it's been appealing to do redirects was for flashdata error messages. In the case I went ahead and had the page post to itself, I'd need to either emulate the same error messages outside of flashdata or fake the flashdata. Either I lose the flashdata errors or I lose the form validation.

Or maybe I should rethink the way I'm handling this sort of thing altogether Smile
#4

[eluser]Thorpe Obazee[/eluser]
Maybe you could post what you're trying to achieve. Anyway, if you "really" want to have additional messages, you could use set_message() of the form_validation class.
#5

[eluser]TheFuzzy0ne[/eluser]
Your controller should only redirect if the form passed the validation, otherwise the same controller method should just keep looping.

Code:
if ($this->input->post('submit'))
{
    # Set rules
    
    if ($this->form_validation->run())
    {
        redirect('somewhere');
    }
}

$data = array(...);
$this->load->view('some_view', $data);




Theme © iAndrew 2016 - Forum software by © MyBB