Parse.com PHP new user


Parse.com PHP new user

我正在搞砸新的 Parse.com php SDK,并且总是对他们的文档感到困惑。他们说要添加新用户,您可以使用如下代码:

$user = new ParseUser();
$user->set("username", "my name");
$user->set("password", "my pass");
$user->set("email", "email@example.com");
// other fields can be set just like with ParseObject
$user->set("phone", "415-392-0202");
try {
  $user->signUp();
  // Hooray! Let them use the app now.
} catch (ParseException $ex) {
  // Show the error message somewhere and let the user try again.
  echo "Error: " . $ex->getCode() . " " . $ex->getMessage();
}

我了解这里发生了什么,但这是一种设置用户的硬编码方式。如果我想要一个注册表单,如何将其合并到他们的代码中?我在想你可以做的是:

<form action="" method="post">
    <p><input id="email" name="email" type="text" placeholder="Email"></p>
    <p><input id="password" name="password" type="password" placeholder="Password">
</form>
<? php 
   $email = $_POST['email'];
 ?>

只是传递电子邮件,例如$user->set("email", $email);.这行得通吗?

一些建议:

  • 在使用变量之前,应首先测试是否发出了POST请求$_POST;
  • 您可能应该对您的输入进行一些验证,例如检查它是否真的在电子邮件字段中包含电子邮件地址;
  • 就个人而言,我会将所有控制器的东西(处理输入)放在顶部,将 html 输出放在最后。

所以像这样:

if ($_SERVER['REQUEST_METHOD'] === 'POST')
{
  // process / filter input
  // store input
}
if (no_post_or_input_not_valid)
{
  // show form
}