Results 1 to 5 of 5

Thread: Temporarily store form data (retrieve after restart)

  1. #1

    Thread Starter
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,123

    Question Temporarily store form data (retrieve after restart)

    Our form has lots of fields and we would like to be able to temporarily save it before submitting so even if there was a sudden power interruption the user could still restore it. Is cookie the way to go or is there a better alternative?

    TIA
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  2. #2
    Hyperactive Member coothead's Avatar
    Join Date
    Oct 2007
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    284

    Re: Temporarily store form data (retrieve after restart)

    Hi there dee-u,

    you could try javascript's "localStorage".

    further reading:-


    Here is an basic form example that I made for you to try...
    Code:
    
    <!DOCTYPE html>
    <html  lang="en">
    <head>
    
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    
    <title>localStorage example</title>
    
    <style media="screen"></style>
    
    <script>
    (function() {
       'use strict';
    
       var el,c;
    
    function init(){ 
    
       el=document.getElementById('theForm').elements;
    for(c=0;c<el.length;c++) { 
       el[c].value=localStorage.getItem('name'+c);
       el[c].addEventListener('keyup',makeHandler(c));
     }
    
    function makeHandler(c) {
       el[c].onkeyup=function() {
       localStorage.setItem('name'+c,el[c].value);
       };
      }
     }
       window.addEventListener('load',init,false);
    })();
    </script>
    
    </head>
    <body>
    
    <form id="theForm" action="#">
     <input type="text">
     <input type="text">
     <input type="text">
     <input type="text">
     <textarea></textarea>
    </form>
    
    </body>
    </html>
    My tests in IE11 proved to be problematic.

    That browser only worked when when running from a
    web server (local or remote) using the http:// protocol.

    When trying to open the file locally without a server,
    localStorage appeared to be unavailable.

    Other browsers, though, worked very well.
    Last edited by coothead; Feb 14th, 2015 at 09:19 AM. Reason: tpynig eorrr


    ~ the original bald headed old fart ~

  3. #3

    Thread Starter
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,123

    Re: Temporarily store form data (retrieve after restart)

    Nice one, this worked but will test it further. Are there any conditions where it will not work? We are using Wampserver for this and it will be on the local network.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  4. #4
    Hyperactive Member coothead's Avatar
    Join Date
    Oct 2007
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    284

    Re: Temporarily store form data (retrieve after restart)

    Hi there dee-u,

    Are there any conditions where it will not work?
    I would suggest that you fully study the contents of the link...


    ...that I gave you in my previous post.

    My knowledge of javascript's "localStorage"
    is limited to the example that I gave you.


    ~ the original bald headed old fart ~

  5. #5
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,605
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width