Required Fields

4 minutes
Share the link to this page
Copied
  Completed
Some fields cannot be empty, lets cover this in this video.

Transcript

Hello, in this video I am going to cover required fields. So a required field is basically a field that has to, you know, you know, you really need a field or you know, for example, if you create your own website creating a new account, you know, required fields will usually be your username, your password, email address, an optional field could potentially be your date of birth, it could be your location, it could be a variety of other things, but they will generally be optional. So how do we cover you know, required fields so in this video, what we are going to look at is basically fixing this error of properties in here, we get this error if they if something is not defined, it's sunset data hasn't been sent. So all what we can do can do this for me post and get say if you know, empty and this is the same if this is empty, then go into brunch.

We can just literally put this I'm literally going to echo the name empty. And else I'm literally going to echo out Do you remember what happened? I'll start with in echo dollar user name I'm going to put this now. So if I reload if I put something in here, the username is here we haven't handled password yet but if I do it for password says username is undefined next on line 51. Now if I type something in the password is finally said username is empty. And now we let's do the same for password.

So password there we go and it should be flip flop. We can like put this in here. The reality is I'll leave it there. We'll leave it there for now. And for reload this for do that those two empty by typing say my name I click enter, we get that password is empty for leave the username empty in a password in my work, we get password username of them too. And if we put both of them in now we don't get any of those no annoying notices, but we haven't really though we are displaying the error message.

It's not in a proper fashion because now most of the validation will occur, you know, at the top here before we do our HTML, and we might actually have something else here, we might just have an h1 that say something like, you know, login. And I forget that we get that looks fine. But what will happen if I do this, we don't want error messages just at the top, they need to be relative to you know what they are referring to, so they need to be positioned accordingly. Therefore, we will handle displaying the error messages properly in the next video, and we'll cover more validation over the next few videos as well. So that's it. If you have any questions, feel free to pop me a message, if you have memory said if you have any question, yeah, feel free to shoot me a message and I look forward to seeing you in the next video.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.