Jump to content

Automatic form submission after sometime

Go to solution Solved by jazzman1,

Recommended Posts


I want to submit the form automatically after sometime,. I have written the code , but its not redirecting/submitting. Don't know why.. Have a look


<!DOCTYPE html>
<script type="text/javascript">
echo"Start Time: ".$starttime=date('H:i:s')."<br/><br/>"; 

<form action="inde x1.php" method="post" id="exam" name="exam">

	Q1 Your Gender<br/>
	<input type="radio" value="male" name="gender"> Male

	<input type="radio" value="female" name="gender"> Female
	<br /><br /><br />
	Q2 You Married<br/>
	<input type="radio" value="yes" name="marriage"> Yes

	<input type="radio" value="female" name="marriag e"> No
	<br /><br /><br />

	Q3 2+2<br/>
	<input type="radio" value="4" name="add"> 4

	<input type="radio" value="22" name="add"> 22
	<input type="hidden" value="<?php echo $starttime; ?>" name="starttime"><br/>
	<input type="hidden" value="<?php echo $startstamp; ?>" name="startstamp"><br/>
	<input type="submit" name="submit">

</ html>
Link to comment
Share on other sites

There is a problem.. No value is displaying on index1.php


Here is the code for index1.php


	echo "Start time: ".$starttime."<br/>";
	echo "End time: ".$endtime=date('H:i:s')."<br/>";

	echo "Time-taken : ".$timetaken=($endstamp-$startstamp)/60;

Link to comment
Share on other sites

Thanks jazzman1 , that works.

but i can't get the logic.


The submit method submits the specified form as if a submit element (button) was pressed. But the problem is that you also have in the form  a submit object element whose property name is using the same name (submit). So, when you set a property name to submit (it doesn't matter which type of the form), you override the submit() function on the form.


@To the 2nd question, most likely you need to change if(isset($_POST['submit'])) to if(isset($_POST['send'])), where $_POST('send') is the name of the submit button.

Edited by jazzman1
Link to comment
Share on other sites

  • Solution

Because js submit() method works like <button type="submit"> Click Me</button>, so the button element isn't as input elements, when the form is being submitted it's omitted from the form. Just create an input hidden element and check its value in the server side. 

Link to comment
Share on other sites

you can make this simple test to see what I'm talking about,

<form name="f1" action="display.php" method="post">  
        <input type="text" name="test_input" value="some input text" />
        <input type="submit" name="test_submit" value="query" />
        <button type="submit">Click Me!</button>



Array ( [test_input] => some input text )

Edited by jazzman1
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.

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.