Jump to content

PHP post without button


edd12345678

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/256480-php-post-without-button/
Share on other sites

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

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.