Welcome Guest, Not a member yet? Register   Sign In
Possible reasons for form_error not being populated?
#1

[eluser]Unknown[/eluser]
I have what I think is a fairly standard setup, controller with two methods, one which outputs a form, one which processes said form. The processor method uses the CI form_validation thing, I believe in a fairly normal way, it basically does this

Code:
if ($this->form_validation->run($validation_config) == FALSE)
$this->display_form($code);
} else {
// Sets up some flashdata to say success
redirect('/display_form')
}

If you fill in the form properly and it validates correctly then the flashdata is set and it correctly redirects to the form displayed with the correct flash-message.

However if you fail validation then the error messages are not displayed in the form for some reason.

The processor uses one of three possible validation configs depending on some setup, I know that's working as I've echoed it right before it gets called. It doesn't matter which specific config it uses, the behaviour is the same for all of them.

If I add debug to the bit above like so

Code:
if ($this->form_validation->run($validation_config) == FALSE)
echo "FEName ".form_error('name');
echo "FEEmail: " . form_error('email');
die();
$this->display_form($code);
} else...

Then I see the correct error messages.

But if I remove that from there and add it to the top of the display_form method, then neither message appears. Which explains why they are not coming out in the view. But I don't understand how they can disappear in between those two points.

Does anyone have any idea how this can happen? I have an almost identical set-up with a different form, that one works as expected.

I should add this was working a while ago but I've done a tonne of development since then and suddenly I just realised this one form is now not validating properly and I just cannot see why.
#2

[eluser]Unknown[/eluser]
Gah, worked it out. Logic was flawed, the process method was continuing after the call to this->display_form and then doing a redirect and losing all the data.




Theme © iAndrew 2016 - Forum software by © MyBB