添加密码到表单

时间:2014-07-04 08:15:50

标签: php html5 forms

我正在尝试创建一个表单,用户需要使用我提供的密码。 因此,当用户提交表单时,他们必须在表单中键入“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\">";
}
?>

2 个答案:

答案 0 :(得分:0)

可能你可以试试这个......

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

答案 1 :(得分:0)

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

您可以尝试使用此代码,对您有所帮助。