Let's go through the signup process step-by-step, in which we'll rebuild the code in our signup POST
route from scratch. I'll explain each piece of code on the way, and then, we will do a full recap at the end of this section.
1. Open
index.php
, and start by collecting the simple fields:full_name, email
, androles
. The fieldsfull_name
andemail
will come directly from the form submission, androles
we will set to an empty array because this user has no special permissions.post('/signup', function($app) { $user = new User(); $user->full_name = $app->form('full_name'); $user->email = $app->form('email'); $user->roles = array();
2. Next, we'll want to capture the username that the user submitted, but we'll want to safeguard against weird characters or spaces, so we'll use a regular expression to convert the posted username to a lowercase string without any special characters. The end result will serve as our
name
field and also...