将密码添加到表单


Add Password to Form

我正在尝试创建一个表单,要求用户使用我给他们的密码。因此,当用户提交表格时,他们必须在表格中键入"Password123",然后才能将表格提交到我的电子邮件中。但是,如果他们弄错了密码,网站会重定向到错误页面。

到目前为止,我一直收到一个内部服务器错误。

这是html:

    <form method="post" action="contactengine.php">
<div class="forms">
                <h4>PASWORD: <input type="password" placeholder="******" name="Password" /></h4>
                <h4>YOUR NAME: <input type="text" placeholder="Smith Family" name="Name" /></h4>
                <h4>YOUR CITY: <input type="text" placeholder="Anytown, USA"name="City" /></h4>
                <h4>YOUR TELLEPHONE: <input type="text" placeholder="123.456.7891"name="Tel" /></h4>
                <h4>YOUR EMAIL: <input type="text" placeholder="you@emaildomain.com" name="Email" /></h4>
                <h4>MESSAGE TO US:</h4> <textarea width="10000px" name="Message" placeholder="Go ahead and say something nice to us!" rows="20" cols="20" id="Message"></textarea>
                <br>
                <input type="submit" name="submit" value="Submit" class="submit-button" />
            </form>
</div>

这是PHP:

<?php
$Password = Trim(stripslashes($_POST['Password']));
$EmailFrom = "me@gmail.com";
$EmailTo = "me@gmail.com";
$Subject = "THIS IS THE SUBJECT";
$Name = Trim(stripslashes($_POST['Name'])); 
$Tel = Trim(stripslashes($_POST['Tel'])); 
$Email = Trim(stripslashes($_POST['Email'])); 
$Message = Trim(stripslashes($_POST['Message'])); 
// THIS IS WHERE I AM STUCK
    if ($Password != "Password123") {
      print "<meta http-equiv='"refresh'" content='"0;URL=error.htm'">";
      exit;
    }

$validationOK=true;
if (!$validationOK) {
  print "<meta http-equiv='"refresh'" content='"0;URL=error.htm'">";
  exit;
}
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "'n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "'n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "'n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "'n";

$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

if ($success){
  print "<meta http-equiv='"refresh'" content='"0;URL=contactthanks.php'">";
}
else{
  print "<meta http-equiv='"refresh'" content='"0;URL=error.htm'">";
}
?>

也许你可以试试这个。。。

 if ($Password != "Password123") {
      echo "<script language='javascript'> window.location='error.htm'; </script>";
      exit;
    }
if ($Password != "Password123") {
echo "<script>document.location.href='new.php'</script>";
}

你可以试试这个代码,可能对你有帮助。