0

I am messing around with the new Parse.com php SDK and like always a little confussed with their docs. They say to add a new user you can use code like this:

$user = new ParseUser();
$user->set("username", "my name");
$user->set("password", "my pass");
$user->set("email", "[email protected]");

// 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();
}

Which I understand whats going on here but that is a hard coded way to set a user. If I want a signup form how do incorperate that into their code? I was thinking of you can just do:

<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'];
 ?>

the just pass the email for example like $user->set("email", $email);. Would that work and be best practice??

1 Answer 1

1

Some recommendations:

  • You should first test if a POST request was made before you use $_POST variables;
  • You should probably do some validation on your input, like checking if it really contains an e-mail address in the e-mail field;
  • Personally I would put all the controller stuff (processing the input) at the top and the html output at the end.

So something like:

if ($_SERVER['REQUEST_METHOD'] === 'POST')
{
  // process / filter input

  // store input
}

if (no_post_or_input_not_valid)
{
  // show form
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, that makes sense for sure. I guess the real question would be then would using a post variable like that to set up a user be the right way?
@Packy Yes, using a form and POST is a logical and common way to collect and process user input.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.