开发者

Form Textbox Caching Problem

开发者 https://www.devze.com 2022-12-13 09:20 出处:网络
I have a PHP form, with various input fields and textboxes. If you submit and go back, all of the data that was submitted in the input fields remains, however the textboxes are blank. How can I get th

I have a PHP form, with various input fields and textboxes. If you submit and go back, all of the data that was submitted in the input fields remains, however the textboxes are blank. How can I get the data entered in the textbox 开发者_运维百科to cache like the regular text inputs?


This is a client-side issue. Although there's no way to force the browser to cache the textarea input you can send the data back yourself using cookies if you want. One easy way to do so would be to store the textarea input in cookies when the form is submitted and then to check for the cookies and insert the values into the page source on subsequent requests to the server.

Check out this page for information on setting the cookies and this one to learn how to access the information the next time your form is accessed.


I generally prefer the back button myself, but if you want to re-populate all your fields, an alternative is to have the form page submit to self and then do like this:

<form action="whatever" method="POST">
<input type="text" size="20" name="text_field" value="<?php echo $_POST['text_field']; ?>">
<textarea name="text_area"><?php echo $_POST['text_area']; ?></textarea>
<input type="submit" value="Submit">
</form>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号