Jamie Redmond
Jamie Redmond

Reputation: 731

Sending Error Messages to Another Page?

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

Answers (3)

Hugo Mota
Hugo Mota

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

NikiC
NikiC

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

Marc B
Marc B

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

Related Questions