php - Submit form after countdown finishes -
i'm trying submit document (return_url
) after countdown finishes. in current code below document submitted after countdown starts. how can make countdown finish before submitting document_url
?
code:
<body> <center> <form name="redirect"><font face="helvetica"><b> thank you! redirected in<input type="text" size="1" style="font-size:25px" name="redirect2">seconds.</b></font> </form></form> </center> <form name="return_url" method="post" action="confirm.php"> <input type="hidden" name="order" value="1" /> <input type="hidden" name="price" value="100" /> </form> </body> </html> <script language="javascript" type="text/javascript"> var targeturl="<?php print_r($_post['url_retorno']);?>" var countdownfrom=10 var currentsecond=document.redirect.redirect2.value=countdownfrom+1 function countredirect(){ if (currentsecond!=1){ currentsecond-=1 document.redirect.redirect2.value=currentsecond } else { window.location=targeturl return } settimeout("countredirect()",1000) } countredirect() document.return_url.submit() </script>
big point, shouldn't automatically submit forms users, it's kind of bad ux design. instead, wait before submiting thing disables button until timer up. , that, need make use of javascript timers.
var timer = window.setinterval(updateclock,1000); var countdown = 10; function updateclock() { countdown--; if(countdown<=0) { window.clearinterval(timer); //allow form submit document.getelementbyid("elementid").disabled = false } else { document.getelementbyid("elementid").value = "please wait "+countdown+" seconds"; } }
i'm adding in side point should never trust people put forms. lookup xss or cross site scripting, , sql injection find out why. need use validation (even numbers). if want on page validation (which still isn't secure since can by-passed) add onsubmit="validate()"
attribute form tag call validate()
function when user submit it. using function gives power take on form if needed, since can execute javascript want there , returning "false" value cause form not submit.
always validate form entries on server level (ie. in confirm.php file)
Comments
Post a Comment