1
00:00:00,840 --> 00:00:06,000
So we're almost done our server side form validation, and here's where we are right now, we can try

2
00:00:06,000 --> 00:00:10,080
to submit this form and these three are currently required.

3
00:00:10,110 --> 00:00:10,830
This one is not.

4
00:00:11,520 --> 00:00:12,990
And this actually works.

5
00:00:13,000 --> 00:00:17,730
I can actually try this make reservation and it will say no, got to be at least three characters so

6
00:00:17,730 --> 00:00:18,690
I could make that three.

7
00:00:19,170 --> 00:00:25,050
And but the problem is here under email, I can put just a letter and that accepts it.

8
00:00:25,050 --> 00:00:25,680
It's fine.

9
00:00:25,680 --> 00:00:28,230
And we want that to verify that it's actually an email.

10
00:00:28,920 --> 00:00:30,060
So we can do that.

11
00:00:30,690 --> 00:00:33,840
You can do it manually and it's rather lengthy and difficult.

12
00:00:34,410 --> 00:00:36,090
But there's a simple way to do this.

13
00:00:36,090 --> 00:00:39,660
And this is a package I mentioned a little while ago called Go Validator.

14
00:00:40,080 --> 00:00:41,610
It's a very good package.

15
00:00:41,610 --> 00:00:43,260
It's been around for a long time.

16
00:00:43,260 --> 00:00:48,240
It's been well tested and I've been using it for, well, pretty much shortly after it came out.

17
00:00:48,870 --> 00:00:49,820
So let's install that.

18
00:00:49,830 --> 00:00:51,300
So the URL is right here.

19
00:00:51,720 --> 00:00:57,570
Go to GitHub Dotcom as a K in the Chicago validator.

20
00:00:58,380 --> 00:01:03,120
So go there and you go down to the install part and we're going to use this version.

21
00:01:03,120 --> 00:01:07,620
We're not going to use this version because it's not really set up for packages correctly and it doesn't

22
00:01:07,620 --> 00:01:09,000
matter for our purposes right now.

23
00:01:09,300 --> 00:01:16,100
We'll just copy this, go back to our project, make sure a terminal window is open and paste that in,

24
00:01:16,140 --> 00:01:17,550
make sure you're in the correct directory.

25
00:01:17,550 --> 00:01:20,440
So I am right now on a Mac, at least I can type.

26
00:01:20,490 --> 00:01:24,900
Would you make sure you're in the correct directory on Windows?

27
00:01:24,900 --> 00:01:29,670
And you will notice that I moved my project out of visual studio code into goaland projects.

28
00:01:29,910 --> 00:01:32,400
Just cleaner for me because that's where I put most of my go code.

29
00:01:33,000 --> 00:01:36,090
So I'm going to paste in this, go get command.

30
00:01:36,570 --> 00:01:37,620
It will go and get it.

31
00:01:37,620 --> 00:01:38,220
And there it is.

32
00:01:38,700 --> 00:01:39,890
Now we want to use it.

33
00:01:40,530 --> 00:01:44,820
So what we need to do, first of all, is to set up a validator.

34
00:01:45,150 --> 00:01:48,480
We want to set up a Veldheer that checks that something is an email.

35
00:01:48,870 --> 00:01:50,820
So I will hide my terminal window.

36
00:01:50,940 --> 00:01:58,320
I'm going to go to my forms page or forms go code and write at the very bottom.

37
00:01:58,320 --> 00:02:02,360
I'll put in a new [REMOVED] func and again, it's for effort.

38
00:02:02,370 --> 00:02:03,870
It takes the receiver for form.

39
00:02:03,870 --> 00:02:05,370
So I'll use that and I'll just call.

40
00:02:05,370 --> 00:02:06,540
This is email.

41
00:02:06,750 --> 00:02:07,770
That's all I have to do.

42
00:02:08,460 --> 00:02:13,230
And what I'm going to be checking again, as usual, is a field which will be passed as a string and

43
00:02:13,230 --> 00:02:14,460
that's all I need to pass it.

44
00:02:15,120 --> 00:02:21,480
And all I'm going to do is called go validator and go validator is really, really good at validation.

45
00:02:21,960 --> 00:02:28,230
So if I don't want to check to make sure that this is an email, so I'll check to see if I get a response

46
00:02:28,230 --> 00:02:35,340
of Fault's from calling go validator and it actually puts it in there for me in my autocomplete.

47
00:02:35,340 --> 00:02:40,520
But I don't want abs and I just want to check his email and pass it.

48
00:02:40,540 --> 00:02:47,250
Feel sorry, not pass at the field, pass it the form object, the pointer that we have, the form object,

49
00:02:47,640 --> 00:02:55,440
get the function on that and, and the field is field so that will get whatever the user typed into

50
00:02:55,860 --> 00:02:57,780
whatever field name we've passed here.

51
00:02:57,780 --> 00:03:04,800
We call dars email in our forms that will go to the form post, look for the entry labeled email and

52
00:03:04,800 --> 00:03:05,340
get the value.

53
00:03:06,060 --> 00:03:12,550
And if, if that of course fails that check, what do I do?

54
00:03:12,580 --> 00:03:13,860
Same thing I've been doing right along.

55
00:03:13,860 --> 00:03:21,990
F dot errors dot add and add an error for this field and the error is invalid.

56
00:03:22,170 --> 00:03:23,820
Email address.

57
00:03:24,930 --> 00:03:26,460
All right, now let's give this a comment.

58
00:03:26,910 --> 00:03:33,240
Keep things nice and neat checks for valid email address.

59
00:03:33,390 --> 00:03:33,780
All right.

60
00:03:33,810 --> 00:03:41,490
So I've added that as a new validator so I can go back to my handlers over here, find the post for

61
00:03:41,730 --> 00:03:46,380
reservation right here and add another check form.

62
00:03:46,380 --> 00:03:53,850
DOT is email and I'm checking the of the form field email, and that's all I have to do.

63
00:03:54,240 --> 00:04:00,450
So let's run our application, go run command web, start up, go.

64
00:04:01,770 --> 00:04:08,250
Let's go back to our page on our site and reload it to make sure that we actually can do this properly.

65
00:04:08,700 --> 00:04:10,920
Let's make sure all the other validations work.

66
00:04:11,220 --> 00:04:14,400
They do that one works.

67
00:04:14,400 --> 00:04:18,750
Now let's put an AI in here, which is not a valid email address, invalid email address.

68
00:04:19,020 --> 00:04:25,470
Let's put a at a invalid email address and now let's make a valid email address.

69
00:04:26,820 --> 00:04:28,230
That one is valid there.

70
00:04:28,320 --> 00:04:32,010
There's our VM email validation and that's all we really need to do for this.

71
00:04:33,030 --> 00:04:34,620
So that was pretty straightforward.

72
00:04:34,620 --> 00:04:35,610
In the next lecture.

73
00:04:35,610 --> 00:04:38,520
What I want to do is when this form is filled out properly.

74
00:04:38,520 --> 00:04:42,030
So I have enough valid information in here to get past the check.

75
00:04:42,080 --> 00:04:44,010
I don't need phone right now.

76
00:04:44,490 --> 00:04:45,750
It displays a blank screen.

77
00:04:45,840 --> 00:04:51,990
I want I want to do in the next lecture is actually display the results of our reservation.

78
00:04:51,990 --> 00:04:56,220
And as you probably guessed, we really don't have enough information on our form right now to make

79
00:04:56,220 --> 00:04:57,180
a true reservation.

80
00:04:57,720 --> 00:04:58,650
We have the first name.

81
00:04:58,650 --> 00:04:59,730
We have the last name we have.

82
00:04:59,760 --> 00:05:03,450
The email we had, the phone, we don't know what room they're making a reservation for and there's

83
00:05:03,450 --> 00:05:07,180
other information we want as well, but we'll add that as time goes on.

84
00:05:07,410 --> 00:05:12,060
Right now, we're just getting our validation working and we can create all the validators we think

85
00:05:12,060 --> 00:05:12,420
we need.

86
00:05:13,050 --> 00:05:15,380
So in the next election, we'll make sure that we do fill this out.

87
00:05:15,390 --> 00:05:17,160
You don't get a blank screen.
