#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    204
    Rep Power
    2

    Form validation Array to previous page


    Hi!

    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.
    Thanks!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,397
    Rep Power
    594
    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.
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    204
    Rep Power
    2
    Originally Posted by gw1500se
    What do you mean "previous page?" PHP is stateless. That means once it outputs a page, it loses all information regarding it.
    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?

    thanks!
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2001
    Location
    knee deep in sh*t
    Posts
    254
    Rep Power
    65
    Originally Posted by notflip
    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?

    thanks!
    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:

    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,
    oach
  8. #5
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    204
    Rep Power
    2
    Originally Posted by oach
    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:

    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,
    oach
    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!

    Thanks for the nice response!
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2004
    Posts
    2,972
    Rep Power
    375
    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..

IMN logo majestic logo threadwatch logo seochat tools logo