我正在搞乱新的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);
。这会起作用并成为最佳实践吗?
答案 0 :(得分:1)
一些建议:
POST
变量之前,您应首先测试是否发出了$_POST
请求; 类似于:
if ($_SERVER['REQUEST_METHOD'] === 'POST')
{
// process / filter input
// store input
}
if (no_post_or_input_not_valid)
{
// show form
}