开发者

Auto Submitted form does not carry form variables

The following form does not carry form variables when it is submitted using quto javascript after 5 seconds.

Normal submission works fine.


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<SCRIPT LANGUAGE="JavaScript"><!--
setTimeout('document.test.submit()',5000);
//--></SCRIPT>

</head>
<body>
<form name="test" id="form1" method="post" ac开发者_运维知识库tion="auto2.php">
  <p>
    <INPUT TYPE=checkbox NAME="test" VALUE="option1"> Option1
    <INPUT TYPE=checkbox NAME="test" VALUE="option2"> Option2
    <INPUT TYPE=checkbox NAME="test" VALUE="option3"> Option3   
  </p>
  <p><input type="submit" name="submit_test" value="Submit_test" />
&nbsp;  </p>
</form>
</body>
</html>
---------------------------------------------------------------

output page:

--------------------------------------------------------------
<?php

if(isset($_POST['submit_test'])){
$variable=$_POST['test'];

echo $variable;

}

?>

Any help is highly appreciated.. thank you.


You are testing whether the submit_test button value is set:

if(isset($_POST['submit_test'])){

Submitting the form automatically won't set the value, so your test fails.

You should test for some other form field, like a hidden element.


Unless a checkbox is checked, you wont get any response (blank or otherwise)

What you should have instead is

<input type=hidden name="test" value="">
<INPUT TYPE=checkbox NAME="test" VALUE="option1"> Option1
<INPUT TYPE=checkbox NAME="test" VALUE="option2"> Option2
<INPUT TYPE=checkbox NAME="test" VALUE="option3"> Option3  

That way you get a default value when you post your form


+1 to Pekka's answer.

If you do the following it will check to see that the page was posted to without requiring that a variable was set in the post.

if ($_SERVER['REQUEST_METHOD'] === 'POST') { ... }

You should probably also put in some form of validation to make sure it came from where you expected it to.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜