2015-10-16 107 views
1

我有一個HTML表單,我希望在文檔準備好後的4000毫秒後提交此表單,而不需要單擊提交按鈕。但我需要隱藏的數據在控制器中,同時提交 它怎麼可能?請幫幫我?如何在延遲後提交表格

<form action="<?echo base_url();?>register/form_success" method="post" class="form-horizontal" id="career_submitform"> 
          <div class="control-group"> 
           <span class="caption-title">Please complete the registration form for getting the admission application number</span> 

          </div> 
          <input type="hidden" value="<? echo $applicant_id?>" name="applicant_id"> 
          <input type="hidden" value="<? echo $grade_name?>" name="grade_name"> 
          <input type="hidden" value="<? echo $grade_id?>" name="grade_id"> 
          <div class="form-actions clearfix"> 
           <div class="btncontinue-wrap"> 
            <input type="submit" value="Continue" name="submit" class="btn-d btn-continue blue button-next" id="button_submit_style"> 
           </div> 
          </div> 
         </form> 
+1

所以更好,你必須使用AJAX –

+0

使用jQuery **延遲()**功能。 –

回答

2

使用jQuery做延遲

$(function() { 
    $('#career_submitform').delay(2000).submit(); 
}); 
+0

頁面不重定向 –

0
<form action="<?echo base_url();?>register/form_success" method="post" class="form-horizontal" id="career_submitform"> 
          <div class="control-group"> 
           <span class="caption-title">Please complete the registration form for getting the admission application number</span> 

          </div> 
          <input type="hidden" value="<? echo $applicant_id?>" name="applicant_id"> 
          <input type="hidden" value="<? echo $grade_name?>" name="grade_name"> 
          <input type="hidden" value="<? echo $grade_id?>" name="grade_id"> 
          <div class="form-actions clearfix"> 
           <div class="btncontinue-wrap"> 
            <input type="button" onclick="myFunction()" value="Continue" name="submit" class="btn-d btn-continue blue button-next" id="button_submit_style"> 
           </div> 
          </div> 
         </form> 

<script> 
function myFunction() { 
    $('#career_submitform').delay(4000).submit(); 
} 
</script> 
+0

它不起作用 –

2

然後使用這個樣子。 HTML部分:

<form id="career_submitform"> 
    <input type="text"> 
    <button>Submit</button> 
</form> 

腳本部分:

$("#career_submitform").submit(function (e) { 
    var form = this; 
    e.preventDefault(); 
    setTimeout(function() { 
     form.submit(); 
    }, 1000); 
    $("<p>Working...</p>").appendTo("form"); 
}); 

檢查http://jsfiddle.net/eoko1ap4/