EchoFool Posted March 23, 2010 Share Posted March 23, 2010 Hey, How do people make forums such as phpfreaks - where by if you press the back button your input values are not lost in the text area ? I tried with sessions, but that can be problematic in itself. Or is it some kind of HTML cache thing? Link to comment https://forums.phpfreaks.com/topic/196303-form-remembering-values/ Share on other sites More sharing options...
o3d Posted March 23, 2010 Share Posted March 23, 2010 If there are no javascript executed on the form when the page loaded then when you click the back button you should have the values filled in as when the form was submitted and if there were no re-directions performed. Link to comment https://forums.phpfreaks.com/topic/196303-form-remembering-values/#findComment-1030826 Share on other sites More sharing options...
EchoFool Posted March 23, 2010 Author Share Posted March 23, 2010 Oh so its browser cache not php ? Link to comment https://forums.phpfreaks.com/topic/196303-form-remembering-values/#findComment-1030827 Share on other sites More sharing options...
seaweed Posted March 23, 2010 Share Posted March 23, 2010 Why are sessions problematic? When you send the form, on the receiving page just create temp variables like this: if ($error_exists or some other condition) { $_SESSION['username'] - $_POST['username']; $_SESSION['phone'] - $_POST['phone']; header("Location: form.html"); exit; } and then on the form itself echo out the values if they are not empty like this: <form> <input type="text" name="username" value="<?php echo $_SESSION['username']; ?>" /> <input type="text" name="phone" value="<?php echo $_SESSION['phone']; ?>" /> </form> and then maybe kill the session values so they don't get re-used $_SESSION['username'] = null; $_SESSION['phone] = null; Link to comment https://forums.phpfreaks.com/topic/196303-form-remembering-values/#findComment-1030840 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.