javascript if(isset($_POST['submit'])) 两次不工作第二次
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5269656/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
if(isset($_POST['submit'])) twice not working second time
提问by Denoteone
I am pulling my hair out. I had this working earlier.
我正在拔头发。我早些时候有这个工作。
My confirm.phpchecks variables from the previous page's form. Then echos them so the viewer can confirm the answers. If everything looks good they can click the paypal image name="submit"and it goes through the isset again and sends mail()and updates the URL for the form action then post variables to paypal with some javascript code I got help with earlier.
我confirm.php检查上一页表单中的变量。然后回显它们,以便观众可以确认答案。如果一切看起来都不错,他们可以单击贝宝图像name="submit",它再次通过 isset 并发送mail()和更新表单操作的 URL,然后使用一些我之前得到帮助的 JavaScript 代码将变量发布到贝宝。
EDIT:I upload more streamline code:
编辑:我上传了更精简的代码:
form.php page:
form.php 页面:
<form action="test.php" method="post">
Name: <input type="text" name="name" value=""/>
<input type="submit" name="send" value="send"/>
</form>
Confirm.php:
确认.php:
<?
ini_set("display_errors","2");
ERROR_REPORTING(E_ALL);
$url = '';
if (isset($_POST['send']))
{
$data = $_POST['name'];
}else{
echo "SEND is not Set";
}
if (isset($_POST['submit']))
{
$data = $_POST['data'];
$my_message = ' TEST DATA:<br/><br/>Child Name'. $data .'';
$subject = 'Mike TEST';
$headers = "From: [email protected]\r\n";
$headers .= "Reply-To: [email protected]\r\n";
$headers .= "Content-type: text/html\r\n";
$url = "https://www.paypal.com/cgi-bin/webscr";
mail("[email protected]",$my_message,$subject,$headers);
}else{
echo "SUBMIT is not Set";
}
?>
<html>
<head>
</head>
<body>
<form action="<? echo $url; ?>" method="post">
Name: <? echo $data; ?><input type="hidden" name="data" value="<? echo $data; ?>"/><br/><br/>
<input type="submit" value="submit" name="submit">
</form>
<?
if ($url != "") {
?>
<script language="javascript">
document.forms[0].submit();
</script>
<?
}else{ echo "URL NOT SET";}
?>
</body>
</html>
回答by Shakti Singh
When your form submit it set variables in $_POSTas
当您的表单提交时,它会将变量设置$_POST为
$_POST['Submit_x'] $_POST['Submit_y']
That's why your condition fails every time.
这就是为什么您的条件每次都失败的原因。
You are checking with the $_POST['submit']PHP is the case sensitive in respect of variable names.
您正在检查$_POST['submit']PHP 在变量名称方面是否区分大小写。
回答by Marc B
value="<? echo $data; ?>"?
This is bad practice. if $datacontains a double-quote, it'll break your form. As is, blindly outputting user-provided data is exactly how XSS attacks occur. You should have, at bare minimum:
这是不好的做法。如果$data包含双引号,它会破坏您的表单。实际上,盲目输出用户提供的数据正是 XSS 攻击发生的方式。你应该至少有:
value="<?php echo htmlspecialchars($data) ?>">
which'll keep your form intact.
这将保持您的表格完好无损。
回答by konsolenfreddy
Your submit tag is written with a capital 'S':
您的提交标签是用大写的“S”写的:
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_paynowCC_LG.gif" border="0" name="Submit" alt="PayPal - The safer, easier way to pay online!">
but your PHP is checking for a lowercase 'submit'.
On an additional note, I would add a hidden field with the name submit, older IEs don't submit the value of a submit button (at least not input type="submit"don't know about input type="image"though)
但是您的 PHP 正在检查小写的“提交”。另外要注意的是,我会添加一个名为 submit 的隐藏字段,较旧的 IE 不提交提交按钮的值(至少不是input type="submit"不知道input type="image")
<input type="hidden" name="submitted" value="1">
in your PHP check for
在你的 PHP 检查中
if (intval($_POST['submitted']) > 0)

