Jaswinder Posted April 2, 2014 Share Posted April 2, 2014 Hi 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 Thanks <!DOCTYPE html> <html> <head> <script type="text/javascript"> setTimeout(function(){document.getElementById("exam").submit()},2000); </script> </head> <body> <?php date_default_timezone_set('Asia/Kolkata'); echo"Start Time: ".$starttime=date('H:i:s')."<br/><br/>"; $startstamp=time(); ?> <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"> </form> </body> </ html> Link to comment https://forums.phpfreaks.com/topic/287467-automatic-form-submission-after-sometime/ Share on other sites More sharing options...
gristoi Posted April 2, 2014 Share Posted April 2, 2014 action="inde x1.php" to action="index1.php" Link to comment https://forums.phpfreaks.com/topic/287467-automatic-form-submission-after-sometime/#findComment-1474724 Share on other sites More sharing options...
Jaswinder Posted April 2, 2014 Author Share Posted April 2, 2014 Oh sorry.. thats a copy/paste error.. Its not working yet.. Any other help Link to comment https://forums.phpfreaks.com/topic/287467-automatic-form-submission-after-sometime/#findComment-1474728 Share on other sites More sharing options...
jazzman1 Posted April 3, 2014 Share Posted April 3, 2014 Change name="submit" to something else, for instance - <input type="submit" name="send" /> Link to comment https://forums.phpfreaks.com/topic/287467-automatic-form-submission-after-sometime/#findComment-1474861 Share on other sites More sharing options...
Jaswinder Posted April 4, 2014 Author Share Posted April 4, 2014 Thanks jazzman1 , that works. but i can't get the logic. Link to comment https://forums.phpfreaks.com/topic/287467-automatic-form-submission-after-sometime/#findComment-1474966 Share on other sites More sharing options...
Jaswinder Posted April 4, 2014 Author Share Posted April 4, 2014 There is a problem.. No value is displaying on index1.php Here is the code for index1.php <?php if(isset($_POST['submit'])) { extract($_POST); echo "Start time: ".$starttime."<br/>"; echo "End time: ".$endtime=date('H:i:s')."<br/>"; $endstamp=time(); echo "Time-taken : ".$timetaken=($endstamp-$startstamp)/60; } ?> Link to comment https://forums.phpfreaks.com/topic/287467-automatic-form-submission-after-sometime/#findComment-1474984 Share on other sites More sharing options...
jazzman1 Posted April 4, 2014 Share Posted April 4, 2014 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. Link to comment https://forums.phpfreaks.com/topic/287467-automatic-form-submission-after-sometime/#findComment-1475005 Share on other sites More sharing options...
Jaswinder Posted April 5, 2014 Author Share Posted April 5, 2014 Thanks for reply That was a silly mistake on my part Now, I changed it to if(isset($_POST['send'])) Still blank page, but i tried this if(!isset($_POST['send'])) Now it showing , so the question is, why script is not setting it ? Link to comment https://forums.phpfreaks.com/topic/287467-automatic-form-submission-after-sometime/#findComment-1475010 Share on other sites More sharing options...
jazzman1 Posted April 5, 2014 Share Posted April 5, 2014 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 https://forums.phpfreaks.com/topic/287467-automatic-form-submission-after-sometime/#findComment-1475013 Share on other sites More sharing options...
jazzman1 Posted April 5, 2014 Share Posted April 5, 2014 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> </form> Result: Array ( [test_input] => some input text ) Link to comment https://forums.phpfreaks.com/topic/287467-automatic-form-submission-after-sometime/#findComment-1475017 Share on other sites More sharing options...
Jaswinder Posted April 7, 2014 Author Share Posted April 7, 2014 Thanks , that hidden trick works Link to comment https://forums.phpfreaks.com/topic/287467-automatic-form-submission-after-sometime/#findComment-1475193 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.