Remember contents of INPUT and AREA?

Discussion in 'Web Design and Development' started by Corbin052198, Jul 8, 2011.

  1. Corbin052198, Jul 8, 2011
    Last edited: Jul 8, 2011

    Corbin052198 macrumors 6502

    Corbin052198

    Joined:
    Mar 13, 2010
    #1
    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:
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    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.
     
  3. Corbin052198 thread starter macrumors 6502

    Corbin052198

    Joined:
    Mar 13, 2010
    #3
    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?
     
  4. angelwatt, Jul 8, 2011
    Last edited: Jul 8, 2011

    angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #4
    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).
     
  5. Corbin052198 thread starter macrumors 6502

    Corbin052198

    Joined:
    Mar 13, 2010
    #5
    Thanks. Since my web application already does not support older browsers anyway, I think I'll try the HTML5 brower storage technique.
     

Share This Page