使用POST处理表单

时间:2016-07-26 09:55:17

标签: javascript php forms

我正在处理表单和表单处理程序。方法是_POST,我使用 PHP 处理它。现在,当我想处理表格时,它说$username未定义。

我的表格:

<html>
  <head>
    <title>Register</title>
    <script type="text/javascript" src="includes/register_form_validator.js" ></script>
  </head>
  <body>
    <form method="post" action="includes/register_form_handler.php" name="register_form" >
      <label for="username" >Username :</label><input placeholder="username" type="text" /><br>
      <label for="password">Password :</label><input type="password" name="password" /><br>
      <label for="cpassword">Confirm Password :</label><input type="password" name="cpassword" /><br>
      <label for="email">E-Mail :</label><input type="email" name="email" onChange="" /><br>
      <input type="submit" value="Submit" />
    </form>
  </body>
</html>

处理程序:

<?php
// Do a Form Validation , Makes sure that resource is Valid///////////
$actual_link = "http://$_SERVER[HTTP_HOST]" . "/dcreview/register.php";
if (!isset($_SERVER['HTTP_REFERER'])) {
  echo "Invalid Form";
  exit;
} else {
  if ($_SERVER['HTTP_REFERER'] != $actual_link) {
    echo "Invalid Form";
    exit;
  }
}
///////////////////////////////////////////////////////////////////
// Processes Form //
$user = $_POST["username"];
$pass = $_POST['password'];
$email = $_POST['email'];

password_hash($pass, PASSWORD_BCRYPT);
?>

2 个答案:

答案 0 :(得分:3)

用此行替换您的用户名HTML

<label for="username" >Username :</label><input name="username" placeholder="username" type="text"  /><br>

答案 1 :(得分:3)

您的用户名没有name属性。使用此:

<input name="username" placeholder="username" type="text" />