douzhe1264 2010-07-21 07:34
浏览 26
已采纳

Jquery自动表单提交,但什么都不返回

I'm using Keith Jquery Countdown 1.5.8 for doing the countdown and the ticking time is working perfectly for every user. i have 2 forms in a single php file (let's say multiform.php) but the form submits nothing when the countdown reaches zero.

Here is my jquery code :

<script type="text/javascript">
$(function () {
    $('#defaultCountdown').countdown({until: <?php echo($usertime); ?>,
    onExpiry: function() {
        $('#quizform').submit();
    }
    });
});
</script>

and some of my multiform.php codes are :

<?php
    if($choice==1) {
?>
...
<form action="submit.php" method="post" name="quizform" id="quizform">
...
...
<input type="submit" name="save_1" value="Save" />
</form>

<?php
    } else {
?>
...
<form action="submit.php" method="post" name="quizform" id="quizform">
...
...
<input type="submit" name="save_2" value="Save" />
</form>

and submit.php consists of :

if(isset($_POST['save_1'])) {
    ...do part 1
}
else {
    ...do part 2
}

The form submits nothing, none of those text input values submitted to "submit.php". It returns blank. Am i doing wrong ?

  • 写回答

1条回答 默认 最新

  • dsf4354353452 2010-07-21 11:18
    关注

    I think I have the solution here - from memory, when you submit a form using Javascript, as opposed to clicking the "submit" button, the values held in the "submit" button are not carrier through.

    Example:

    <form method="post" action="submit.php">
      <input name="field1" value="One">
      <input name="field2" value="Two">
      <input type="submit name="save" value="Save">
    </form>
    

    When submitted via clicking on the "Save" button will return

    $_POST = array( 'field1'=>'One' , 'field2'=>'Two' , 'save'=>'Save' );
    

    If submitted via Javascript it will return

    $_POST = array( 'field1'=>'One' , 'field2'=>'Two' );
    

    To resolve this, add a hidden field containing the value you want transmitted, regardless of the method

    <form method="post" action="submit.php">
      <input type="hidden" name="formID' value="TheFirstForm">
      <input name="field1" value="One">
      <input name="field2" value="Two">
      <input type="submit name="save" value="Save">
    </form>
    

    Which will return, via a click of the button

    $_POST = array( 'formID'=>'TheFirstForm' ,'field1'=>'One' , 'field2'=>'Two' , 'save'=>'Save' );
    

    And with a Javascript submission

    $_POST = array( 'formID'=>'TheFirstForm' ,'field1'=>'One' , 'field2'=>'Two' );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大