Reputation: 731
When a user creates their own account, if there is an error I want to redirect them to the same page but display the errors at the top.
What's the best way to do this?
Upvotes: 0
Views: 448
Reputation: 11567
i like to create a function named set_feedback()
that sets the error in a session variable. then i have this other function get_feedback()
that retrieves the information and unset the variable.
Upvotes: 1
Reputation: 101946
I save the error into the session and remove it once it was rendered. As you will probably abort the pages execution on a redirect it will never reach the code responsible for rendering thus leaving it in the session.
Upvotes: 0
Reputation: 360872
Structure your page as follows (in rough pseudo-code)
if (doing a post) {
process input
if (post is ok) {
redirect to success page
} else {
build error messages
}
}
if (error messages available) {
display errors
}
display form(filled in with previously submitted values)
Upvotes: 3