PHP - form validation and error messages

Associate
Joined
21 Sep 2007
Posts
453
Ok, so I am trying to build some forms with basic validation (check for empty fields) and error reporting.

I am currently trying to use sessions, with some success, but I am now getting a bit stuck.

So far I have got the form to check for blank input values. If the input is blank/NULL then an error message gets pushed into an array.

If there is at least 1 array entry, the array is then stored in a session. The form is reloaded, and the error messages are displayed under the relevant input boxes.

The problem I am facing is that if I navigate away form the form page, and back again, the session is still there.

Is there a way for me to clear the stored array from the session when leaving the page? I would do it when the user enters the page, but ofc when it gets reloaded to show the errors, it would clear them away before displaying them!

EDIT - haha, I am a total noob. Just tried putting the code to destory the session at the end of my page, and its working nicely. Please delete/lock this thread :)
 
Last edited:
Back
Top Bottom