在20秒内自动提交表格

时间:2017-01-23 04:31:28

标签: javascript php jquery angularjs ajax

我正在尝试自动提交此表单20秒,但有些错误并且无法正常工作,我没有任何错误消息,我使用此作为起点从URL获取用户名和密码并替换此登录并提交

中的相应字段



<form accept-charset="UTF-8" role="form" class="form-signin"
  id="form" name="{$form_name}" action="{$form_action}" method="post" encType="multipart/form-data" onsubmit="return validateForm('{$form_objectRequiredFields}');">
  <input type="hidden" class="notValidateThisFields" name="__notValidateThisFields__" id="__notValidateThisFields__" value="{$form_objectRequiredFields}" />
  <input type="hidden" name="DynaformRequiredFields" id="DynaformRequiredFields" value="{$form_objectRequiredFields}" />
  {$form.BROWSER_TIME_ZONE_OFFSET}
    <div style="display: none;"> {$form.USR_PASSWORD}</div>
    <fieldset>
      <label class="panel-login">
        <div class="login_result"></div>
      </label>
      {$form.USR_USERNAME}
      {$form.USR_PASSWORD_MASK}
      {$form.USER_LANG}
      {$form.URL}
      {$form.FAILED_LOGINS}

    </fieldset>
    <fieldset>
        <label class="panel-login">
            <div class="login_result"></div>
        </label>
        <br>
        {$form.BSUBMIT}
        {$form.FORGOT_PASWORD_LINK}

    </fieldset>
    <script type="text/javascript">
      {$form.JS}
    </script>
	<script>
	window.onload=function() {literal}{{/literal}
		var x = 20;
		var y = document.getElementById("timer");
		
	
		setInterval(function(){literal}{{/literal}
		 if( x<=21 && x>=1)
		{literal} { {/literal}
			x--;
			y.innerHTML= ''+x+'';	
			
			if(x==1)
			{literal}{{/literal}
			 x=21;
			{literal}} {/literal}
		{literal}} {/literal}
		
		{literal}}{/literal}, 1000);
		
	

    var auto_refresh = setInterval(function() {literal}{{/literal} submitform(); {literal}}{/literal}, 20000);

	
	function submitform()
	{literal} { {/literal}
		alert('Form is submitting.....');
		   document.getElementById("form").submit();
		
	{literal} } {/literal}
	</script>
</form>
<script src="/lib/pmdynaform/libs/respondjs/respond.min.js"></script>
<script src="/lib/pmdynaform/libs/html5shiv/html5shiv.js"></script>
<script type="text/javascript">
    try {literal}{{/literal} dynaformSetFocus();}catch(e){literal}{{/literal}}
</script>
&#13;
&#13;
&#13;

3 个答案:

答案 0 :(得分:3)

试试这个

 button.onclick=function(){ 
        button.setTimeout(function() { document.formId.submit(); }, 20000);
    };

答案 1 :(得分:2)

试试这个:

$(function(){  // document.ready function...
   setTimeout(function(){
      $('formId').submit();
    }, 20000);    // In milliseconds - 20 seconds is given here
});

答案 2 :(得分:1)

您可以尝试使用window.setTimeout()来执行基于毫秒的函数。

window.setTimeout(submitform, 20000);

函数submitform将在20000ms后执行