edd12345678 Posted February 5, 2012 Share Posted February 5, 2012 Hello everyone, I wonder if anyone can help me. I have a timer which when the time expires I want any data in my form to be submitted to the database. Is it possible to use post without having a button to trigger it? So: e.g if(($_SESSION['endOfTimer'] - time()) < 0) { Insert values to the database? } How can I do this so it posts the data without the use of a button? Thanks in advance. Ed Quote Link to comment https://forums.phpfreaks.com/topic/256480-php-post-without-button/ Share on other sites More sharing options...
attaboy Posted February 5, 2012 Share Posted February 5, 2012 After reading your post I spent a few minutes looking and seems you have to use javascript for that maybe with a settimeout() function. I don't know enough about either javascript or php to be much help....good luck. Quote Link to comment https://forums.phpfreaks.com/topic/256480-php-post-without-button/#findComment-1314859 Share on other sites More sharing options...
zeodragonzord Posted February 6, 2012 Share Posted February 6, 2012 You can use a combination of the submit() and settimeout() JavaScript functions. This is untested, but you can try something like this. function submitForm() { document.forms["theFormName"].submit(); } setTimeout("submitForm()",5000); Quote Link to comment https://forums.phpfreaks.com/topic/256480-php-post-without-button/#findComment-1315024 Share on other sites More sharing options...
edd12345678 Posted February 6, 2012 Author Share Posted February 6, 2012 Hi, Many thanks for your reply. Is the set timeout() needed for the timer or is it calling the submitFunction function every 5 seconds? At the moment I cannot get it to work. Also at the moment I do not have a form set up as such. I just have: if(isset($_POST["save"])){ Then run query } Thanks Edd Quote Link to comment https://forums.phpfreaks.com/topic/256480-php-post-without-button/#findComment-1315214 Share on other sites More sharing options...
zeodragonzord Posted February 6, 2012 Share Posted February 6, 2012 setTimeout() only runs once. You might be thinking of setInterval(), which runs repeatedly. However, if you're using setTimeout() to submit a form back to the same page, well then your page will just run setTimeout() over and over again on each page load. I just tried this out and this works. <script type="text/javascript"> function submitForm() { document.forms["theFormName"].submit(); } setTimeout("submitForm()",2000); </script> <form name="theFormName" id="theFormName" action="receiving_page.html"> <input type="text" name="field1" id="field1" value="field1value"> <input type="text" name="field2" id="field2" value="field2value"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/256480-php-post-without-button/#findComment-1315245 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.