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' );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!