2

i want to save the post data to user pc before posting just incase of bad internet connection where it happens a lot in my area.

most of the time users write article , add images and when clicking submit button their connection is lost due to some issues .

so is there is a way in php , ajax , jquery . that i can do to save that while typing or before posting so if internet connection goes wrong , they can return when it is up and post ?

Hussein
  • 97
  • 11
  • 3
    Yes, what you are looking for is called "local storage". See e.g. [Javascript + HTML5 localstorage](http://stackoverflow.com/q/2800238) – Pekka Dec 01 '13 at 18:05

3 Answers3

1

CODE :

    function saveEditsBeforeSend(inputIdThatyouWantToGrabState){

        var contentOfInput = $(inputIdThatyouWantToGrabState).val();

        $.cookie("userInputContentOf"+$(inputIdThatyouWantToGrabState).attr("id"), contentOfInput); 

}

Add a event listerner and call it before send

    $("#yourFormId").on("submit", function(e){
        e.preventDefault();
        var form = $(this);         
        saveEditsBeforeSend(form.find("#inputIdThatyouWantToGrabState"));
        form.trigger("submit");     
});

This code will store content of input in cookies that you can use later when the connection will be ok. (Note that this content will be lost if the user lost his session) Thats an idea you can perfectionize it

e-Learner
  • 517
  • 1
  • 4
  • 15
0

Add a submit listener to your form, prior submitting save all the form input values in the browser's local storage. In older browsers (IE) you can "polyfill" this non-existent functionality.

Have a look at this list of browser storage polyfills.

bagonyi
  • 3,162
  • 2
  • 19
  • 20
0

HTML5 includes a spec called LocalStorage, which allows you to store some information in the clients browser like cookies has in the past. This method is great because cookies are tiny in size and very insecure.

There is a nice article about it here: http://diveintohtml5.info/storage.html

scrowler
  • 23,403
  • 9
  • 52
  • 87