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').countdow开发者_StackOverflow中文版n({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 ?
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' );
精彩评论