January 25th, 2013, 06:28 AM
Form validation Array to previous page
I have a page comment.php which check if all forms are filled in and add's the new comment.. but if there's an error i trap it inside an array with errors... now..
How can i send the Errors array to the previous page and show it there.
January 25th, 2013, 07:08 AM
What do you mean "previous page?" PHP is stateless. That means once it outputs a page, it loses all information regarding it.
There are 10 kinds of people in the world. Those that understand binary and those that don't.
January 25th, 2013, 08:39 AM
Well my form is on post.php?p=2 , the comment is validated on comment.php and if it shows errors i want the errors to show up above the form on post.php?p=2 ? so how would i do that... or is it better if i put the code of comment.php on the same page?
Originally Posted by gw1500se
January 25th, 2013, 08:48 AM
It is up to you how you handle it. I find it easier to work on the same page if there are errors. Off the top of my head here are different ways you could handle:
Originally Posted by notflip
1. Same page, checking if the post has been submitted, if yes, process, if not, show form. If no errors, enter the comment our pass to your comment page for processing.
2. Use an ajax call to your comment.php page. If it returns errors show some div or other ui to display errors.
3. Do the way you are thinking, but pass back some error message in the query string or similar to the original page. Let the original page check to see if an error is set and display. Set it in the session maybe. But that seems strange to me (maybe because I have never done it)
I hope that helps,
January 25th, 2013, 08:55 AM
I'm going for the validation-code-on-same page. i thought it would be cleaner to do it on a seperate page.. but didn't think about how to return the errors.. I'll learn it the ajax way soon!
Originally Posted by oach
Thanks for the nice response!
January 25th, 2013, 11:03 AM
you can do validation on another page.. just store a session[error] or soemthing and if there are errors take user back to the form page and output those errors..