Auto save form using PHP, jQuery


This blog is regarding how to auto save form using PHP, jQuery. There are many tutorial available but it is very simple method.

HTML Form :

<form id=”auto-save-form”>
Name : <input name=”name” type=”text” />
Email : <input name=”email” type=”text”>
<input name=”submit” type=”submit”/>
</form>

JQuery Code:

/*Form Auto Submit Logic*/
var changeFlag = false;
var focusFlag = false;
jQuery(“#auto-save-form”).change(function () {
changeFlag = true;
focusFlag = false;
});

setInterval(function () {
/*
* changeFlag for change any element of current form
* focusFlag for tell us that focus out or in
*/
if (changeFlag == true && focusFlag == false) {
jQuery(“#auto-save-form”).trigger(“submit”);
changeFlag = false;
}

}, 10000);

jQuery(“#auto-save-form input”).focus(function () {
focusFlag = true;
});
jQuery(“#auto-save-form input”).focusout(function () {
focusFlag = false;
});

/*Form Auto Submit Logic End*/
$(“#auto-save-form”).submit(function() {
//Ajax Logic
alert(“submitted”);
});

Download Demo

I hope you understand this tutorial. If you have any questions or confusion then please comment it..


Comments

3 responses to “Auto save form using PHP, jQuery”

  1. Thank you ๐Ÿ™‚
    Code is working fine.

    Liked by 1 person

  2. Thank you !
    Its very helpful for auto save form.

    Liked by 1 person

  3. […] via Auto save form using PHP, jQuery โ€” Help on PHP […]

    Like

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.