heldenbrau Posted September 4, 2009 Share Posted September 4, 2009 If somebody fills out a form and they click the back button by mistake and go back, the text is gone from the text box. On this forum, if I do that, the text is still here when I come back. How can I get my text boxes to do this? Quote Link to comment https://forums.phpfreaks.com/topic/173124-how-do-you-keep-the-text-to-stay-in-the-text-box/ Share on other sites More sharing options...
JonnoTheDev Posted September 4, 2009 Share Posted September 4, 2009 I think this forum will use ajax to make the post rather than a standard form submission. Quote Link to comment https://forums.phpfreaks.com/topic/173124-how-do-you-keep-the-text-to-stay-in-the-text-box/#findComment-912500 Share on other sites More sharing options...
heldenbrau Posted September 4, 2009 Author Share Posted September 4, 2009 but most online forms keep the text in the box. Like order forms, when you put your name and address in. Quote Link to comment https://forums.phpfreaks.com/topic/173124-how-do-you-keep-the-text-to-stay-in-the-text-box/#findComment-912503 Share on other sites More sharing options...
SilveR316 Posted September 4, 2009 Share Posted September 4, 2009 Ajax is one possibility. The other possibility is repopulating the form based on the submitted data in $_POST. <input type="text" name="username" value="<?php echo $_POST['username']; ?>" /> Quote Link to comment https://forums.phpfreaks.com/topic/173124-how-do-you-keep-the-text-to-stay-in-the-text-box/#findComment-912611 Share on other sites More sharing options...
bundyxc Posted September 4, 2009 Share Posted September 4, 2009 Quote Link to comment https://forums.phpfreaks.com/topic/173124-how-do-you-keep-the-text-to-stay-in-the-text-box/#findComment-912673 Share on other sites More sharing options...
JonnoTheDev Posted September 5, 2009 Share Posted September 5, 2009 The other possibility is repopulating the form based on the submitted data in $_POST. Yes, normally but that wouldn't work if the back button is clicked as stated in the post. This forum uses ajax to save the data in a form so the page is not reloaded, that is why the data persists. A cookie is a dumb idea! You don't store form data in cookies to maintain persistence. If I was logging into my online bank account would it be wise to store my account details in a cookie? Quote Link to comment https://forums.phpfreaks.com/topic/173124-how-do-you-keep-the-text-to-stay-in-the-text-box/#findComment-913094 Share on other sites More sharing options...
bundyxc Posted September 5, 2009 Share Posted September 5, 2009 Oof, didn't think about that. I thought that the 'go back' was more of a browser thing? Quote Link to comment https://forums.phpfreaks.com/topic/173124-how-do-you-keep-the-text-to-stay-in-the-text-box/#findComment-913275 Share on other sites More sharing options...
corbin Posted September 5, 2009 Share Posted September 5, 2009 I think it's entirely the browser, and nothing to do with anything server side. Quote Link to comment https://forums.phpfreaks.com/topic/173124-how-do-you-keep-the-text-to-stay-in-the-text-box/#findComment-913284 Share on other sites More sharing options...
kratsg Posted September 5, 2009 Share Posted September 5, 2009 I think it's entirely the browser, and nothing to do with anything server side. If you let your browser cache and save form field data, then it will do it... however, you can use sessions to force it to repopulate if you want. Quote Link to comment https://forums.phpfreaks.com/topic/173124-how-do-you-keep-the-text-to-stay-in-the-text-box/#findComment-913353 Share on other sites More sharing options...
bundyxc Posted September 5, 2009 Share Posted September 5, 2009 I think it's entirely the browser, and nothing to do with anything server side. If you let your browser cache and save form field data, then it will do it... however, you can use sessions to force it to repopulate if you want. But by hitting 'Back' you don't actually reload the page, so it really doesn't even matter what's changing server-side, as it's not being reloaded... which is why I suggested cookies, which are stored client-side. Obviously you just have to be picky about which forms you want to save. Quote Link to comment https://forums.phpfreaks.com/topic/173124-how-do-you-keep-the-text-to-stay-in-the-text-box/#findComment-913365 Share on other sites More sharing options...
kratsg Posted September 5, 2009 Share Posted September 5, 2009 I think it's entirely the browser, and nothing to do with anything server side. If you let your browser cache and save form field data, then it will do it... however, you can use sessions to force it to repopulate if you want. But by hitting 'Back' you don't actually reload the page, so it really doesn't even matter what's changing server-side, as it's not being reloaded... which is why I suggested cookies, which are stored client-side. Obviously you just have to be picky about which forms you want to save. Best practice would be to use sessions, there are times when sensitive form data should not be kept client-side but rather server-side (cookie grabbers, etc...) Quote Link to comment https://forums.phpfreaks.com/topic/173124-how-do-you-keep-the-text-to-stay-in-the-text-box/#findComment-913372 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.