djp1988 Posted October 1, 2010 Share Posted October 1, 2010 Hello to all,I have been a web developer for some time now, and one thing I always cringe in my web developments is how I manage error screens, being the developer, I know that if for example I navigate to a certain url, I can see an error message I put there, but it's not relevant because it's not a follow up to a real error.Say for example I try to send a message to someone, so on my site I have an inbox, a sent box and a create new message page, if I make my message and submit, the form gets processed, if among my PHP process there's something wrong, like a row didn't get entered into the database, I want to then tell the user something went wrong.I like to keep the PHP processing logic away from the web pages so what I might do is send the form to a handle_message.php page and that then does the magic and then redirects to the relevant page after.I do this to avoid someone refreshing and submitting a form again.But when an error occurs I find myself sometimes redirecting to a url such as: http://domain.com/messages.php?error=1And then I'd display a message, thats all fine if there was a message, but now I don't feel I'm managing this in the best way because I could just manually goto this url and see some message I shouldn't see...That's just an example, I know I can submit to the same page and handle error along with the post / get data, but I really wanted to avoid the user being able to resubmit a form.How do you manage these kinds of situations ?Thanks Link to comment Share on other sites More sharing options...
Synook Posted October 2, 2010 Share Posted October 2, 2010 You can set a temporary session variable when the error occurs, that prompts the next page (you could, say, redirect back to the form) to display the message. Then that page deletes the session variable. You could even put the logic for this in a universally included file (e.g. the header), so the functionality is consistent across all your pages. if (!empty($_SESSION['error'])) { echo "<p class=\"error\">There has been an error: {$_SESSION['error']}.</p>"; unset($_SESSION['error']);} Link to comment Share on other sites More sharing options...
boen_robot Posted October 2, 2010 Share Posted October 2, 2010 Personally, I see nothing wrong with letting a user resubmit a request, as long as they have a chance to enter some new (fixed) data.So what I do is to have a login like logic on all forms: have the form, the form processor and the success page in the same file, and show the form itself with error messages and/or highlights when there's an error. If the user comes to the page without entering the required data, they get the form, if they come with wrong data, they get the form with error explanations and a chance to enter correct data, and if they come with valid data, they get whatever they entered the data for. Link to comment Share on other sites More sharing options...
wirehopper Posted October 2, 2010 Share Posted October 2, 2010 I usually display errors on the same page the data was submitted from, because then the user can correct the errors without going back.Using a javascript library like dojo can highlight errors as people type. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.