eldan88 Posted July 15, 2012 Share Posted July 15, 2012 I wanted to know if there is a way to keep text in the input fields if a user hit the refresh button while typing something in a form. As an example how would I keep the users name in a text field, if they type it in the name text field and hits the refresh button. Below is the code Im trying to use as an example.. <td width="232"><input type="text" id="name" name="name" value="<?=$name?>" /></td> Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/265690-preserving-values-in-input-field-after-page-gets-refreshed/ Share on other sites More sharing options...
scootstah Posted July 15, 2012 Share Posted July 15, 2012 I thought browsers did this already? At least, Firefox 13 does. Your example code would work if they submit the form (and if you assign $name to the POST variable), but not on a page refresh. I'm not sure if there is an elegant solution for doing it on page refresh if the browser doesn't do it for you. The only thing that springs to mind is using Javascript to put the form data into a cookie or a PHP session - but neither of those sound like good ideas. Quote Link to comment https://forums.phpfreaks.com/topic/265690-preserving-values-in-input-field-after-page-gets-refreshed/#findComment-1361597 Share on other sites More sharing options...
DavidAM Posted July 15, 2012 Share Posted July 15, 2012 Can I ask Why you want to do this? I really hate that Firefox refuses to clear out my fields when I refresh a page. If I refresh a page, I expect a pristine new copy of the page, that's why I hit REFRESH. When I am testing a form and having trouble with some JS / AJAX / PHP, and I make some code changes and hit REFRESH, it doesn't clear out the form and I have to find some other way to force it to reload the page. I guess, I expect a refresh to be a reload. Am I the only one who thinks like this? Quote Link to comment https://forums.phpfreaks.com/topic/265690-preserving-values-in-input-field-after-page-gets-refreshed/#findComment-1361608 Share on other sites More sharing options...
scootstah Posted July 15, 2012 Share Posted July 15, 2012 Can I ask Why you want to do this? I really hate that Firefox refuses to clear out my fields when I refresh a page. If I refresh a page, I expect a pristine new copy of the page, that's why I hit REFRESH. When I am testing a form and having trouble with some JS / AJAX / PHP, and I make some code changes and hit REFRESH, it doesn't clear out the form and I have to find some other way to force it to reload the page. I guess, I expect a refresh to be a reload. Am I the only one who thinks like this? Eh, I don't find it to be a big deal. I've trained my hands to go for F5 and ctrl+F5 (reload the cache, thus clearing the form fields) instead of the refresh icon. Quote Link to comment https://forums.phpfreaks.com/topic/265690-preserving-values-in-input-field-after-page-gets-refreshed/#findComment-1361668 Share on other sites More sharing options...
carugala Posted July 16, 2012 Share Posted July 16, 2012 Eh, I don't find it to be a big deal. actually it is. I wanted to know if there is a way to keep text in the input fields if a user hit the refresh button while typing something in a form. define "refresh". This is totally client browser issue. or is it? can the server 'refresh' my client browser? typing 'what'? in what 'form'? login yahoo mail, look at no one sends me email. When I click client browser 'refresh' button, what happens? Wait, what if I open multi tabs/winders on yahoo mail... any tab/winder, When I click client browser 'refresh' button, what happens? Wait, login compuserve, login AOL, open a safari winder? Quote Link to comment https://forums.phpfreaks.com/topic/265690-preserving-values-in-input-field-after-page-gets-refreshed/#findComment-1361817 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.