Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Corbin052198

macrumors 6502
Original poster
Mar 13, 2010
285
0
I am writing a web application, and part of it is remembering the contents of a input field and an area text box. Is there any way to do this? HTML5, PHP, JavaScript, anything?

I have tried this for the INPUT element (for PHP):

Code:
<input name="doc1" type="text" class="file-name" placeholder="Type document name here." value="" size="4">

Any ideas about what would work? :confused:
 
Last edited:
For PHP, use the $_SESSION variable to keep track of the content, and place it where you need it. Here's an example that would be of value to you.

I don't have access to my work machine until tomorrow, but looking at this, (and being a PHP beginner) I still have two questions:

1. Can the data be accessed after the browser is quit?
2. Does the form have to be submitted for the data to be saved?
 
1. The $_SESSION expires when the browser closes (or earlier if the code expires it).
2. With $_SESSION yes, it must be submitted because PHP runs on the server, not the browser.

If you want persistent data, that lasts between visits, you'll need to either store it in a database on a server you control (the most common, but involved, and won't get there unless the page is submitted to something that puts it in the DB), use cookies in the browser, or the HTML5 browser storage using SQLite (not supported by older browsers).
 
Last edited:
1. The $_SESSION expires when the browser closes (or earlier if the code expires it).
2. With $_SESSION yes, it must be submitted because PHP runs on the server, not the browser.

If you want persistent data, that lasts between visits, you'll need to either store it in a database on a server you control (the most common, but involved, and won't get there unless the page is submitted to something that puts it in the DB), use cookies in the browser, or the HTML5 browser storage using SQLite (not supported by older browsers).

Thanks. Since my web application already does not support older browsers anyway, I think I'll try the HTML5 brower storage technique.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.