In this episode, we focus on validating the registration form in our application. We'll go through adding the basic validation rules for the user's name, email, and password fields. You'll see how to set up rules like making sure the name is purely alphabetic, the email looks like an actual email address, and none of these fields are left empty.
We'll work directly in the register controller, borrowing some code from our login flow to keep things consistent. I show you how to handle validation errors using a try-catch block, flash error messages to the session, and display those errors back in the form. If you want, feel free to experiment with stricter validations like min/max lengths.
Towards the end, you'll notice there's a problem if someone tries to register with an email that's already taken—the app will throw a SQL error since the email is unique in the database. We'll address this by creating a custom validation rule to check the database before trying to save the user, but that's coming up in the next episode.
If you've already got the hang of form validation from previous lessons, feel free to do this part on your own or skip ahead!