dadamssg Posted January 21, 2009 Share Posted January 21, 2009 ive created a form that reloads and displays an error message when one of the fields is left blank like below if($_SESSION['location'] == "") { $message .= "Please enter a location. "; } but when the page loads back up with the error messages it clears their input, you can click your browsers back button and their input will be there...is there a way that i can make the submit button display the errors but not lose all their input? i have drop-downs and radio buttons in the form as well so i cant just store their input as session variables and redisplay them in the same form..it would lose what they selected in the drop downs and radio buttons....any brilliant ideas? is javascript the answer? Quote Link to comment Share on other sites More sharing options...
RussellReal Posted January 21, 2009 Share Posted January 21, 2009 ok <input type="text" name="location" value="<?php echo $_REQUEST['location']; ?>" /> Quote Link to comment Share on other sites More sharing options...
dadamssg Posted January 21, 2009 Author Share Posted January 21, 2009 how about the selection list? Quote Link to comment Share on other sites More sharing options...
RussellReal Posted January 21, 2009 Share Posted January 21, 2009 ahh u c thats a problem.. you could put the <option> tag's values and html inside an array like $options = array( 'male' => 'Male', 'female' => 'Female' 'other' => 'I\'m A Freak!' ); and then <select name="gender"> <?php foreach ($options as $value => $text) { if ($_REQUEST['gender'] == $value) $selected = " selected='selected'"; echo '<option value="'.$value.'"'.$selected.'>'.$text.'</option>'; $selected = ''; } ?> </select> Quote Link to comment Share on other sites More sharing options...
haku Posted January 21, 2009 Share Posted January 21, 2009 It depends. If your processing script is on the same page as the form, then you can use the method used above, as the $_POST data will exist on the same page. But if your processing script is on a different page, then you need to save the data in a cookie, then check for the existence of the cookie when loading the form. If the cookie exists, then load the data into the form. 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.