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..
Leave a comment