Jump to content

Autosave a Form


fohanlon

Recommended Posts

Hi Guys

 

I want to be able to autosave a form content every X seconds,

 

I coded it using php and javascript getHTTPObject() function but it will not work.

 

Can anyone point me to a php solution to autosave a form

 

Kind Regards,

 

Fergal.

Link to comment
Share on other sites

Hi

 

Below is the code I am using (found after a net search - not mine).  I load init() in body on page load.:

 

function init()

{

    window.setInterval(autoSave, 20000); // 20 seconds

    }

 

 

    function autoSave()

            var status = document.getElementById("status").value;

           

            var params = "?status=" + status;

            var http = getHTTPObject();

http.onreadystatechange = function()

{

if(http.readyState == 4 && http.status == 200) // 200 = HTTP OK

{

// alert(http.responseText);

alert("All data for this current participant has been auto saved");

}

    };

            http.open("POST", "mypageaddress.php" + params, true);

http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

http.setRequestHeader("Content-length", params.length);

http.setRequestHeader("Connection", "close");

            http.send(params);

    }

       

        //cross-browser xmlHTTP getter

        function getHTTPObject() {

            var xmlhttp;

            /*@cc_on

            @if (@_jscript_version >= 5)

                try {

                    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

                }

                catch (e) {                    try {

                        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

                    }

                    catch (E) {

                        xmlhttp = false;

                    }

                }

            @else

                xmlhttp = false;

            @end @*/ 

           

            if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {

                try { 

                    xmlhttp = new XMLHttpRequest();

                } catch (e) {

                    xmlhttp = false;

                }

            }

           

            return xmlhttp;

        }

 

The page will refresh and I have a php function to update mysql tab if($_SERVER["REQUEST_METHOD"] == "POST")

{ }

 

but this is not being executed.

 

Thanks,

 

Fergal.

 

Link to comment
Share on other sites

Try:

//Change:
window.setInterval(autoSave, 20000);   // 20 seconds
//To:
window.setInterval("autoSave()", 20000);   // 20 seconds

//Change:
var params = "?status=" + status;
//To
var params = "status="+status;

 

After all of that, open the page in firefox, and select 'Tools->Error Console'.  Watch the error console for any errors the script might throw.

Link to comment
Share on other sites

Hi Jcbones

 

I did as you mentioned and I put a echo "<script>alert('here');</script>"; message in my php code on form submission but in FF nothing is happening.  Not even the alert I have in the function AutoSave is appearing.  really stuck on this one.  Thanks for the help.

 

Fergal.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.