PHP代码:
<?php
if (isset($_POST['pwsubmitted'])) {
$pwsub=$_POST['pass'];
if ($pwsub != "TEST"){
$s=1;
$msg = "Incorrect Password";
$msg2 = "Try Again";
}
else if ($pwsub == "TEST"){
$s=2;
$msg = "Password Accepted";
$msg2 = "Your Download Is Below";
$msg3 = "";
}
// so I can see what's going on when form submit happens
echo "s="; var_dump($s); echo "</br>";
echo "msg="; var_dump($msg); echo "</br>";
echo "msg2="; var_dump($msg2); echo "</br>";
echo "msg3="; var_dump($msg3); echo "</br>";
}
?>
表格,展示位置如下:
<div class="passform">
<form id="pwform" method="post" action="">
<input type="hidden" name="submitted" value="pwsubmitted" />
<center>
<span class="titleblue">Enter The Password</span>
</center>
<input name="pass" id="pass" type="password" class="password" />
<input name="submit" type="submit" class="submit" style="cursor: pointer;" value="" /></div>
</form>
</div>
其他代码:
<?php
if (isset($_POST['pwsubmitted'])) {
if ($s == 1) { Do This };
if ($s == 2) { Do This };
}
<?php if(!isset($POST['pwsubmitted'])) {
?>
<HTML FORM FROM ABOVE HERE>
<?php } ?>
当我提交表格时......没有任何反应。原始表单保持不变,就像未设置pwsubmitted post变量一样。发生了两件不同的事情,要么是说再次尝试,要么是显示内容。都没有发生。
我做错了什么?
答案 0 :(得分:6)
在您的HTML中,您有此输入字段
<input type="hidden" name="submitted" value="pwsubmitted" />
在您的PHP中,您正在使用
if (isset($_POST['pwsubmitted'])) {
但该字段的名称为submitted
。尝试
if (isset($_POST['submitted'])) {
答案 1 :(得分:1)
您应该检查$ _POST ['submitted'](名称,而不是输入值)。