This episode is for members only

Level up with a premium membership

Join now
Already a member? Sign in to continue
Playing
40. Manually adding validation errors

Episodes

0%
Your progress
  • Total: 4h 32m
  • Played: 0m
  • Remaining: 4h 32m
Join or sign in to track your progress

Transcript

00:00
OK, so let's cover adding manual validation messages when, for example, we log in and the credentials are incorrect. First of all, I've just realized that this copy and paste kept the email.
00:13
So we're going to go ahead and just change that to password. OK, let's go over and try and hit that again. And yet there we go. We get password must not be empty. OK, so if I enter my email address, but I fill in an incorrect password, we're just redirected back at the moment. All we need to do in the logging controller is just flash a message in here.
00:33
So we're going to do exactly the same thing that we did before and manually flash a message to errors. But what we're going to do is create our own structure to this, because we always know that we are using an email key to show the email error. We can just add a custom message in here. So we could say something like could not sign you in or log you in with those details.
00:59
And let's head over and try this out. So the validation works as usual. But if I enter an incorrect password, you can see that we still get this flashed with the validation. Of course, what you could also do is flash that general global message at the top if you wanted to change this up. But you can basically now just add any of these to your errors message back and have whatever you need to be shown in each of the fields.
50 episodes4 hrs 32 mins

Course overview

Starting completely from scratch, build a modern PHP framework with all the features you’d expect.

Whether you’re new to PHP or not, this is a great exercise for learning what happens under the hood, arming you with knowledge you can apply anywhere you use PHP.

We’ll cover routing, controllers, views, the container, accessing the database, models, authentication, config, CSRF protection, exception handling, pagination, validation, flashing messages and much more.

Let’s dive in and build a PHP framework, step-by-step!

Alex Garrett-Smith
Alex Garrett-Smith
Hey, I'm the founder of Codecourse!

Comments

No comments, yet. Be the first to leave a comment.