brad_langdon Posted July 29, 2009 Share Posted July 29, 2009 Hi, When a user submits my form it then goes to "sendmail.php" where it is then checked to see if any of the required fields were left empty etc. So far so good. If a required field has been left blank then I use a header to redirect the user back to the form page while defining a variable as true so that a message will pop p telling them to fill in all required fields etc. My question is this...when I redirect to the form page all of the fields are blank again...how do I redirect while keeping the text that the user has typed out in the form so that they don't have to start from scratch again? Any help would be very appreciated...I have searched for a solution but have had no luck so far. Quote Link to comment Share on other sites More sharing options...
TeNDoLLA Posted July 29, 2009 Share Posted July 29, 2009 You have to store the user entered values somewhere... good choice could be $_SESSION variables. And then if there was error you fill the form from these variables again after redirecting. Quote Link to comment Share on other sites More sharing options...
brad_langdon Posted July 29, 2009 Author Share Posted July 29, 2009 Thanks, I thought that Session variables didn't work with headers. Also, how do you fill the form with variables? Do you just enter the value of the field as a variable? Quote Link to comment Share on other sites More sharing options...
TeNDoLLA Posted July 29, 2009 Share Posted July 29, 2009 You can have some checks when creating your form. See if the session variables are set and if they are you echo the values from them in the form fields. Sample line which will echo $_SESSION['name'] in to the text field if the session variable exists (now it does as it should do after error and redirect). <?php $_SESSION['name'] = 'Bob'; // inside your form... echo '<input type="text" name="name" value="'. $name = isset($_SESSION['name']) ? $_SESSION['name'] : ''.'" />'; ?> Edit: don't forgot to start your session with session_start() in the beginning of every file that you want to use these variables. Quote Link to comment Share on other sites More sharing options...
brad_langdon Posted July 29, 2009 Author Share Posted July 29, 2009 Great, thanks for your help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.