1
00:00:01,430 --> 00:00:06,240
So this time around, we want to improve our validation and we want to do a few things, actually.

2
00:00:06,620 --> 00:00:07,900
So right now we have this.

3
00:00:07,910 --> 00:00:09,310
It displays an error message.

4
00:00:09,500 --> 00:00:13,350
It displays a nice red around it when there's a problem, and that works great.

5
00:00:13,790 --> 00:00:17,580
So we want to add that same kind of logic to all of these.

6
00:00:17,900 --> 00:00:24,740
We also want the form to repopulate with user entered information after an error is detected and the

7
00:00:24,740 --> 00:00:25,710
pages displayed.

8
00:00:25,720 --> 00:00:29,800
So we want the form to be partially filled out and show errors where errors take place.

9
00:00:30,140 --> 00:00:34,520
And we also want to simplify our method of checking for required fields.

10
00:00:34,850 --> 00:00:35,610
So let's get started.

11
00:00:35,840 --> 00:00:40,460
So I want to go back to my code and I'm going to, first of all, go to the Make Reservation page and

12
00:00:40,460 --> 00:00:45,730
I'm going to think about what how I can display information on this particular form.

13
00:00:46,340 --> 00:00:52,100
So this part of the form right here, which is the first name I want this to display, whatever the

14
00:00:52,100 --> 00:00:54,620
user entered, if they've entered information.

15
00:00:54,620 --> 00:00:57,260
But there's an error and I'm displaying this form.

16
00:00:57,500 --> 00:00:58,370
So how do I do that?

17
00:00:58,570 --> 00:00:59,780
Let's go back to our handlers.

18
00:01:00,710 --> 00:01:05,870
And you remember here, when I rendered the template, I actually pasted this data object.

19
00:01:05,870 --> 00:01:12,620
And the data object is a map of typed string interface, which means we can look up things by string

20
00:01:12,620 --> 00:01:14,240
and we can store anything we want in there.

21
00:01:14,510 --> 00:01:20,420
And we stored one value in that map reservation with the value of reservation, which is this, which

22
00:01:20,420 --> 00:01:23,960
is pre populated with the user's information, whatever they enter in the form.

23
00:01:24,650 --> 00:01:29,200
Well, we can do a similar thing up here when we're displaying the reservation page with a get request.

24
00:01:29,210 --> 00:01:30,710
So we first come to that page.

25
00:01:31,220 --> 00:01:41,950
We can actually create a variable called var empty reservation that's of type models, dot reservation.

26
00:01:42,530 --> 00:01:46,760
So that is an empty reservation, but it has all the necessary fields.

27
00:01:47,240 --> 00:01:58,070
So then we can just create another map so we can say data is equal to make map string interface and

28
00:01:58,070 --> 00:01:58,980
put a value in there.

29
00:01:59,030 --> 00:02:07,850
So data reservation and it's important that it has exactly the same name that I'm using down here when

30
00:02:07,850 --> 00:02:09,140
I say data reservation.

31
00:02:09,650 --> 00:02:18,120
So I create that and in that I store my empty reservation and then I just pass that as data.

32
00:02:20,660 --> 00:02:26,870
So now I have an empty reservation the very first time this page is displayed, which means that I can

33
00:02:26,870 --> 00:02:32,180
come in here and on this input I can use an attribute we haven't paid attention to so far, and it's

34
00:02:32,180 --> 00:02:32,840
called value.

35
00:02:32,870 --> 00:02:38,120
So what is the value to be displayed when this form is rendered and when that's going to be equal to

36
00:02:38,120 --> 00:02:39,000
my reservation?

37
00:02:39,980 --> 00:02:41,630
Now, how am I going to get the reservation out of that?

38
00:02:41,660 --> 00:02:47,300
Well, the simplest way to get the reservation out of my data pass to the template is to come up before

39
00:02:47,300 --> 00:02:50,240
I'm going to use it, but in the same block.

40
00:02:50,240 --> 00:02:54,000
So in the content block, I'm going to declare a new variable using a dollar sign.

41
00:02:54,140 --> 00:02:54,830
Kind of feels like.

42
00:02:55,280 --> 00:02:55,850
But it's not.

43
00:02:56,150 --> 00:02:57,380
And I'll just call this race.

44
00:02:57,560 --> 00:03:04,790
And that's going to be equal to I'm assigning of the value of index data, which is from my template

45
00:03:04,790 --> 00:03:05,180
data.

46
00:03:05,330 --> 00:03:07,310
And inside of that I have a reservation.

47
00:03:07,430 --> 00:03:13,280
So I'm storing the value of my empty reservation the first time this page is displayed in a variable

48
00:03:13,280 --> 00:03:14,450
called Sunrise.

49
00:03:14,900 --> 00:03:15,920
So I can copy that.

50
00:03:16,610 --> 00:03:23,720
Come down here and paste it right in here, put my double bass brackets around it or curly brackets

51
00:03:23,720 --> 00:03:26,900
or whatever you want to call them, rez dot first name.

52
00:03:27,750 --> 00:03:34,370
And I can just copy this and do it for all of the fields so I can come down here for last name and change

53
00:03:34,370 --> 00:03:36,410
value to Rez last name.

54
00:03:38,070 --> 00:03:39,260
Make sure there's a space there.

55
00:03:39,980 --> 00:03:41,320
Do the same thing here.

56
00:03:41,330 --> 00:03:42,830
And this one is for email.

57
00:03:42,830 --> 00:03:49,790
So it's red dot email and again case matters because it's actually named email with a capital E in the

58
00:03:50,150 --> 00:03:55,790
models, dot in the model and then phone resort.

59
00:03:56,080 --> 00:04:03,400
So now if I save that and start my application and start it up, does it compile as it does?

60
00:04:03,410 --> 00:04:05,720
So let's go back to our form, reload the page.

61
00:04:05,720 --> 00:04:10,790
So you know, it's a new page, a blank form, and this time I'll leave first name blank because that's

62
00:04:10,790 --> 00:04:12,500
the only required field I have right now.

63
00:04:12,530 --> 00:04:19,330
We're going to make that better in a minute and I'll put Smith John at not some dotcom doesn't matter.

64
00:04:19,330 --> 00:04:22,510
And some phone number five five five three three now.

65
00:04:22,520 --> 00:04:29,990
And I submit this these should be repopulated and they are I get an error message, but these are repopulate.

66
00:04:29,990 --> 00:04:33,140
So I need to fix this error, but I don't have to retype all this.

67
00:04:33,140 --> 00:04:34,010
And that's great.

68
00:04:34,020 --> 00:04:35,220
Now, how did that work?

69
00:04:36,320 --> 00:04:37,520
Well, let's go back to our handlers.

70
00:04:38,420 --> 00:04:43,970
So back to our handlers, which are right here and hide this and look at when it's rendering it the

71
00:04:43,970 --> 00:04:44,650
first time.

72
00:04:45,050 --> 00:04:50,510
So when our roots start right from the beginning, when I hit this page for the first time, make reservation,

73
00:04:50,510 --> 00:04:57,380
I'm going to the reservation handler, which creates an empty reservation, stores it in my data variable

74
00:04:57,590 --> 00:04:59,990
and passes that to the template along with.

75
00:05:00,070 --> 00:05:03,410
An empty form, so all of this is basically pristine.

76
00:05:03,430 --> 00:05:06,380
There is no useful data in there at all, and that's exactly what I want.

77
00:05:06,400 --> 00:05:09,860
The first time the pages rendered when they post the data.

78
00:05:10,000 --> 00:05:15,220
Now it's calling this handler make reservation post and it goes to post reservation.

79
00:05:15,340 --> 00:05:20,590
And that one says pass the form, create a reservation variable.

80
00:05:20,590 --> 00:05:25,120
That's a type models reservation and store, whatever they entered in there, whether it's good, bad

81
00:05:25,120 --> 00:05:27,370
or indifferent data, if they enter nothing, it'll be empty.

82
00:05:27,370 --> 00:05:29,890
If they entered the wrong information, it'll be the wrong information.

83
00:05:30,610 --> 00:05:36,460
Then I create a new form, pass it through my validation, which has one rule right now that has to

84
00:05:36,460 --> 00:05:37,540
have first name.

85
00:05:38,170 --> 00:05:44,170
And if it's not valid, I just pass that reservation object that I created here and I pass the form

86
00:05:44,170 --> 00:05:45,070
that I created here.

87
00:05:45,430 --> 00:05:51,640
So because there's information in both form and data now, it displays on the form and that's all there

88
00:05:51,640 --> 00:05:52,170
is to it.

89
00:05:52,570 --> 00:05:54,160
So let's go back and clean a few things up.

90
00:05:54,820 --> 00:06:00,610
First of all, I want this same error message to do is to be displayed for all of my fields, whatever

91
00:06:00,610 --> 00:06:01,720
the error message may be.

92
00:06:01,720 --> 00:06:03,880
But I can't use my first name here.

93
00:06:03,880 --> 00:06:07,420
I have to use the last name, which I cannot spell right.

94
00:06:08,470 --> 00:06:09,540
Same thing for email.

95
00:06:09,580 --> 00:06:13,000
Might be a different error message, but I definitely if there's an error, I want it displayed.

96
00:06:13,690 --> 00:06:16,300
And the same thing for phone, which is phone.

97
00:06:17,410 --> 00:06:24,850
OK, and I also had this little bit that goes inside the class, so it puts that nice coloring around

98
00:06:24,850 --> 00:06:28,570
the input and look at that, I misspelled label everywhere the label.

99
00:06:30,280 --> 00:06:30,970
That one's right.

100
00:06:31,470 --> 00:06:32,470
No big deal.

101
00:06:33,850 --> 00:06:38,860
Eladio, am I to automatically fix the closing to yours.

102
00:06:38,860 --> 00:06:41,010
Might not check label.

103
00:06:41,770 --> 00:06:44,320
OK, inside class form control.

104
00:06:44,320 --> 00:06:47,320
I could again put that logic with form errors.

105
00:06:47,320 --> 00:06:49,930
Get this time its last name to change that the last name.

106
00:06:49,990 --> 00:06:50,950
Nothing else changes.

107
00:06:51,940 --> 00:07:03,250
And for this one with form errors get this time it's email and then for phone inside that class and

108
00:07:03,250 --> 00:07:05,590
this time it's email and I should work.

109
00:07:06,040 --> 00:07:11,950
So if I come back here now and reload this oh reload it this way by clicking up here in the world bar

110
00:07:11,950 --> 00:07:14,830
and hit enter and try making a reservation.

111
00:07:14,830 --> 00:07:18,670
Now I should get an error message for only the first one, but it should work.

112
00:07:18,670 --> 00:07:22,300
But if I add the required for these three that it'll work for those as well.

113
00:07:22,780 --> 00:07:29,530
Now last time I said, when you look at the handlers which are right here when we're doing the check,

114
00:07:29,530 --> 00:07:34,840
I said it's really awkward to have to put one command for every single required field.

115
00:07:35,230 --> 00:07:42,010
And I suggest that it might be better in our forms package to either change the hands or to add a new

116
00:07:42,490 --> 00:07:43,210
function in there.

117
00:07:43,240 --> 00:07:44,380
So how are we going to do that?

118
00:07:44,410 --> 00:07:46,910
Well, it's actually easier than you might think.

119
00:07:47,110 --> 00:07:50,400
All I want to do is create a new function and I'll put it right here func.

120
00:07:50,560 --> 00:07:58,150
And again, it has to point to the form where a form pointer the receiver and I'm going to call this

121
00:07:58,150 --> 00:07:58,720
when required.

122
00:07:59,380 --> 00:08:05,260
And this one is going to take one name, one parameter fields, but I'm going to make it off type dot,

123
00:08:05,260 --> 00:08:06,550
dot, dot, string.

124
00:08:07,480 --> 00:08:08,470
And you haven't seen that yet.

125
00:08:08,470 --> 00:08:09,400
It doesn't return anything.

126
00:08:09,850 --> 00:08:16,510
This is called a very ADIC function and a very ADIC function says you can have as many types of string

127
00:08:16,510 --> 00:08:22,870
as you want here, which means I can pass that one required field or five required fields or 50 required

128
00:08:22,990 --> 00:08:24,760
fields and it will do everything I want.

129
00:08:24,760 --> 00:08:30,610
And what I'm going to do in the function is range through that field variable, which might have at

130
00:08:30,610 --> 00:08:33,220
least one thing in it, but it might have 10 things in it.

131
00:08:33,220 --> 00:08:37,780
So I'll just go for and I don't care about the index, so I'll use the underscore to ignore it.

132
00:08:38,170 --> 00:08:41,170
Field is assigned the value of.

133
00:08:44,620 --> 00:08:48,160
Range fields and what do I want to do inside there?

134
00:08:48,190 --> 00:08:50,050
Well, let's get the value of that.

135
00:08:50,050 --> 00:08:56,830
So value is equal F, which is our form object, which we got from a receiver and that has a feel,

136
00:08:56,830 --> 00:08:58,300
a function called get.

137
00:08:58,570 --> 00:09:03,110
And I can get the key of the string by string, which is field in this case.

138
00:09:03,130 --> 00:09:08,800
So if I have first name, last name, email, phone, as parameters passed the first time I come through

139
00:09:08,800 --> 00:09:10,570
here, value which I'm going to spell.

140
00:09:10,570 --> 00:09:10,840
Right.

141
00:09:12,190 --> 00:09:13,300
Which I'm eventually going to spell.

142
00:09:13,300 --> 00:09:13,570
Right.

143
00:09:17,460 --> 00:09:24,900
Value will say go to the form object right here, this receiver call the method get, which is right

144
00:09:24,900 --> 00:09:25,320
on that.

145
00:09:25,560 --> 00:09:29,550
It's right in this package forms and get the field named first name.

146
00:09:29,790 --> 00:09:31,740
OK, so I've got it great.

147
00:09:32,040 --> 00:09:35,430
And I say really simple stuff.

148
00:09:35,430 --> 00:09:39,360
If and this is a package we haven't used much, but we will be using it more.

149
00:09:40,320 --> 00:09:48,270
Strings is a built in package in the Go Standard Library and I'm going to call Trem Space, Trem Space.

150
00:09:48,270 --> 00:09:52,200
And all that does is dreamspace from either end of the string, end of the string is empty, will have

151
00:09:52,200 --> 00:09:54,480
nothing, but it'll give me everything I need in here.

152
00:09:54,480 --> 00:10:01,770
So it removes extraneous spaces that the user might have typed in by mistake, if that is equal to nothing.

153
00:10:02,370 --> 00:10:05,600
In other words, if that form has no value.

154
00:10:05,610 --> 00:10:07,700
And of course, I have to put the value in there what I'm trimming.

155
00:10:08,850 --> 00:10:14,340
So when you trimmed the value, when you remove the extraneous spaces from the variable value which

156
00:10:14,340 --> 00:10:18,780
is currently assigned to first name, if that's the first parameter pass to it, if that's equal to

157
00:10:18,780 --> 00:10:20,340
nothing, then what do I want to do?

158
00:10:20,340 --> 00:10:31,050
Just add an error f errors and I'll call the method add and I'm passing at the name of field, which

159
00:10:31,050 --> 00:10:35,580
is what it's when we arrange through the list of fields, it'll be whatever that field currently is

160
00:10:36,150 --> 00:10:37,250
and an error message.

161
00:10:37,500 --> 00:10:44,430
This field cannot be like that's all I have to do and I don't have to do anything else because if this

162
00:10:44,430 --> 00:10:51,720
condition is never met, this adding of an error will never fire, which means I can go back to my handlers

163
00:10:51,870 --> 00:10:58,950
and don't use this this comment that out, I'll just say form required and pass in the fields.

164
00:10:59,040 --> 00:11:05,490
First name, last name and I'll leave one out email Ali Fona.

165
00:11:05,700 --> 00:11:07,500
OK, so I'm not passing that now.

166
00:11:07,500 --> 00:11:11,220
I'm not calling the house function and I'm going to change that in a minute because it will be useful

167
00:11:11,220 --> 00:11:11,760
later on.

168
00:11:12,780 --> 00:11:13,860
But I'm just calling this.

169
00:11:14,220 --> 00:11:20,730
If any of these have an empty string for their value, then form will have an error added to its errors.

170
00:11:20,970 --> 00:11:21,660
A variable.

171
00:11:21,810 --> 00:11:29,580
So let's restart this, close the application, start it back up, go back to our page and see if we

172
00:11:29,580 --> 00:11:30,270
did anything wrong.

173
00:11:30,270 --> 00:11:36,090
So I'll reload the page and I'll just try something different and look, they're required.

174
00:11:36,270 --> 00:11:39,390
Oh, I made a mistake on the form one somehow, which is why I'm testing it this way.

175
00:11:40,080 --> 00:11:41,580
Let's go back and fix that.

176
00:11:41,580 --> 00:11:43,710
So I have to be on the make reservation page.

177
00:11:44,100 --> 00:11:49,020
And I said on the last one I left email there when that should have been phone so I can just go back

178
00:11:49,020 --> 00:11:49,230
here.

179
00:11:50,150 --> 00:11:51,840
It should reload the page.

180
00:11:51,840 --> 00:11:58,050
We rebuild the cache on the lower than it does not go to only three required field because I left my

181
00:11:58,050 --> 00:11:58,860
phone out.

182
00:11:59,220 --> 00:12:00,990
So that works really well.

183
00:12:00,990 --> 00:12:04,680
But what if I feel some information in A, B, C and D?

184
00:12:06,500 --> 00:12:07,490
And it gives me an error.

185
00:12:07,610 --> 00:12:08,810
Let's find out what the error is.

186
00:12:11,320 --> 00:12:17,000
It's got to be in somewhere in my template formed Ayers Target phone Ardizzone, that looks OK.

187
00:12:17,560 --> 00:12:23,410
What I do want to do here is just start commenting things like comment on it and I reload the page and

188
00:12:23,410 --> 00:12:24,650
let it repost the information.

189
00:12:24,670 --> 00:12:25,500
Still got an error there.

190
00:12:25,510 --> 00:12:26,430
So it's not in there.

191
00:12:29,350 --> 00:12:33,570
Save that, reload the page, still have an error.

192
00:12:36,570 --> 00:12:44,520
Commentator, reload the page, still have an error, and I will comment this last one at.

193
00:12:49,670 --> 00:12:51,050
Oh, you know what, I'm done.

194
00:12:51,470 --> 00:12:52,380
I'll be uncommented.

195
00:12:53,330 --> 00:12:54,350
Let me just undo all that.

196
00:12:56,120 --> 00:12:57,680
Of course, it's there's no error.

197
00:12:57,860 --> 00:13:02,090
When I reload this page, it's blank because I passed validation.

198
00:13:02,150 --> 00:13:07,610
So I need to fail validation in order to reload the page, which means I need to go back and uncommented

199
00:13:07,610 --> 00:13:08,360
this last one.

200
00:13:12,280 --> 00:13:15,310
Reload the page there where now this is required.

201
00:13:15,340 --> 00:13:16,180
This is required.

202
00:13:16,190 --> 00:13:17,050
This is required.

203
00:13:17,080 --> 00:13:18,070
This is not so.

204
00:13:18,070 --> 00:13:19,710
I'll put one in here, one in there.

205
00:13:19,720 --> 00:13:22,630
Leave that one empty because it's required and put one in there.

206
00:13:22,640 --> 00:13:26,650
So I should get A, B and C and an arrow displayed on this.

207
00:13:27,040 --> 00:13:28,150
And I do.

208
00:13:28,390 --> 00:13:30,220
That works really well.

209
00:13:30,670 --> 00:13:32,780
What if that's not the only validation I want?

210
00:13:32,800 --> 00:13:37,150
What if I want it to fail if you don't have at least two characters or three characters in first name?

211
00:13:37,360 --> 00:13:40,110
Well, we don't have a validator for that yet, so let's go write one.

212
00:13:40,300 --> 00:13:46,830
It's really easy to go back to our format package reforms page and we will create a new very a new and

213
00:13:46,860 --> 00:13:47,470
a validator.

214
00:13:47,470 --> 00:13:49,390
And this one I'm going to go with.

215
00:13:49,480 --> 00:13:50,590
I'll just write it from scratch.

216
00:13:50,590 --> 00:13:57,760
I don't need to copy and paste func f pointier to form and I'll call this one min length which will

217
00:13:57,760 --> 00:13:59,320
check for the minimum length of the string.

218
00:13:59,620 --> 00:14:01,420
And it needs to know three things.

219
00:14:01,420 --> 00:14:02,950
First of all, what's the field.

220
00:14:03,100 --> 00:14:03,970
And it'll be a string.

221
00:14:05,590 --> 00:14:07,750
Secondly, what's the minimum like you want.

222
00:14:07,750 --> 00:14:09,780
And I'll call that length and that'll be an entry.

223
00:14:10,210 --> 00:14:11,920
And thirdly, what's the request.

224
00:14:12,070 --> 00:14:17,080
And that's going to be R and a pointer to a HTP request.

225
00:14:17,860 --> 00:14:23,050
So I'll pass that on that and it's going to return bool, even though it doesn't have to.

226
00:14:23,110 --> 00:14:23,680
We're going to do that.

227
00:14:23,770 --> 00:14:27,820
OK, so how do we do this.

228
00:14:27,830 --> 00:14:33,160
Well, X is assigned are not formed yet, whatever your field name is.

229
00:14:33,940 --> 00:14:37,240
So that gets us a string and then we just check to see if it's long enough.

230
00:14:37,240 --> 00:14:45,850
If Lenn of X is less than the length, what do I want to do at an error once again, after errors don't

231
00:14:45,850 --> 00:14:51,580
add and it's for a field, so we pass in our field name and the error is this time I'm going to use

232
00:14:51,580 --> 00:14:58,240
my format as print f package or function because I need to put the I need to give them a more meaningful

233
00:14:58,240 --> 00:15:00,930
error message than hope your your fields not long enough.

234
00:15:01,300 --> 00:15:02,470
Well how long does it have to be.

235
00:15:02,470 --> 00:15:07,900
We might as well tell them so we'll say this field must be at.

236
00:15:10,400 --> 00:15:18,230
Liste percent D characters long, and then we'll replace that placeholder percent D with our Ent.,

237
00:15:18,230 --> 00:15:26,690
which we hold length, so we add that error and will return false, even though we're not using using

238
00:15:26,690 --> 00:15:29,270
this bull at some point, this might be useful information.

239
00:15:30,480 --> 00:15:32,060
Otherwise we return trip.

240
00:15:32,780 --> 00:15:37,670
So if this never gets executed because the minimum length is met, that requirement that it returns

241
00:15:37,670 --> 00:15:43,010
true, otherwise it returns false and stops processing because we return that function, return from

242
00:15:43,010 --> 00:15:43,490
that function.

243
00:15:43,520 --> 00:15:46,070
So let's give it a comment in length.

244
00:15:46,880 --> 00:15:51,930
And it says checks for string, minimum length.

245
00:15:52,590 --> 00:15:54,490
OK, so now I have this min length function.

246
00:15:54,680 --> 00:15:55,360
Let's go use it.

247
00:15:56,180 --> 00:16:00,680
So I'm going to on this page like this, be at least three characters long.

248
00:16:01,130 --> 00:16:02,910
So back and find my handlers.

249
00:16:03,620 --> 00:16:04,540
There they are.

250
00:16:05,300 --> 00:16:08,460
And I can get rid of this comic because I'm not using it anymore.

251
00:16:08,960 --> 00:16:12,620
How do I add another rule to my validation while I just call form again?

252
00:16:12,710 --> 00:16:19,100
One of the methods on form, form in length, my field will be first name and the minimum length will

253
00:16:19,100 --> 00:16:19,720
be three.

254
00:16:19,730 --> 00:16:23,900
And it also expects my requests will pass at my request variable, which I have because I'm writing

255
00:16:23,900 --> 00:16:24,830
a handler right there.

256
00:16:25,940 --> 00:16:33,800
Stop the application, run the application, go back to this form, reload the page by highlighting

257
00:16:33,800 --> 00:16:38,030
that you are hitting enter so it doesn't repost the form data and I'll put in a first name.

258
00:16:38,030 --> 00:16:39,290
That's not long enough, eh?

259
00:16:39,680 --> 00:16:47,020
And I'll put in a last name B and an email C or C C and will leave Fome empty because it's not required.

260
00:16:47,300 --> 00:16:49,220
So it should give me an error on this.

261
00:16:49,220 --> 00:16:51,060
But there's actually two errors being generated.

262
00:16:51,410 --> 00:16:55,400
One is actually no, there's only one error being generated on this one.

263
00:16:55,400 --> 00:16:56,840
So I can leave it empty right now.

264
00:16:57,380 --> 00:17:00,290
So this if I do it this way, it's going to generate two errors.

265
00:17:00,290 --> 00:17:03,680
The first one is this field is required and you've given me nothing.

266
00:17:04,020 --> 00:17:09,230
And the second is there's actually a minimum character length requirement on this field.

267
00:17:09,830 --> 00:17:11,180
Which one is it going to display?

268
00:17:11,690 --> 00:17:18,870
It's going to display the one we added in first, because when we call, get on our R.

269
00:17:19,400 --> 00:17:20,090
Where is it here?

270
00:17:21,050 --> 00:17:21,890
It's on our errors.

271
00:17:21,890 --> 00:17:29,390
I think it is when we call get we're returning indexed zero, which is the first thing in that slice.

272
00:17:29,870 --> 00:17:34,650
So here when I filled this out, the first error in that slice is the field cannot be blank.

273
00:17:34,790 --> 00:17:39,110
Now let's put a character in there which still is going to fail because it's not at least three characters

274
00:17:39,110 --> 00:17:40,640
along this field.

275
00:17:40,640 --> 00:17:42,410
Must be at least three three characters long.

276
00:17:42,740 --> 00:17:45,530
And now if I fill it out, it'll submit it and we'll get a blank page.

277
00:17:46,280 --> 00:17:46,610
All right.

278
00:17:46,610 --> 00:17:54,530
Last thing I want to do right now is to go back to our handlers, know our forms.

279
00:17:54,860 --> 00:17:57,680
And I said I was going to make a change to required.

280
00:17:57,830 --> 00:18:00,770
Well, I'm not required to has, but I need a permit for required.

281
00:18:01,340 --> 00:18:02,750
So I'll put a comment in here.

282
00:18:03,470 --> 00:18:06,590
Checks for required fields.

283
00:18:06,800 --> 00:18:07,170
OK.

284
00:18:07,820 --> 00:18:13,970
And it is under has I said, well, I don't want to add an error for this one necessarily and I don't

285
00:18:13,970 --> 00:18:15,340
want an added error for this one.

286
00:18:15,590 --> 00:18:21,860
This will become a useful function because there are certain fields like a checkbox, for example,

287
00:18:22,340 --> 00:18:25,700
that are actually handled differently than a text input.

288
00:18:26,000 --> 00:18:32,480
So when you put a checkbox on a form, if the checkbox is checked, then that value, whatever the input

289
00:18:32,480 --> 00:18:38,600
is named, the input type equals checkbox, if I call mine, agreed to terms and conditions that variable

290
00:18:38,600 --> 00:18:41,900
agree to terms and conditions is passed as part of the post request.

291
00:18:42,230 --> 00:18:45,490
But if it's not not checked, it's not even included at all.

292
00:18:45,500 --> 00:18:46,950
So you can't do anything with it.

293
00:18:47,480 --> 00:18:56,870
So this has will be a useful feature for us to check whether or not submitted form data includes a certain

294
00:18:56,870 --> 00:18:57,290
field.

295
00:18:57,560 --> 00:19:00,600
So I'm going to leave that one alone except for removing that error.

296
00:19:01,220 --> 00:19:04,280
So now it's available to us and we are good to go.

297
00:19:04,430 --> 00:19:09,260
The last thing we need to actually check on this make reservation form the posting, part of it at least,

298
00:19:09,530 --> 00:19:14,870
is that email is really an email and we'll do that in the next package or next lecture, and we'll do

299
00:19:14,870 --> 00:19:19,640
it by importing a third party package called Go Validator, which is really good.

300
00:19:20,060 --> 00:19:21,200
A time tested.

301
00:19:21,200 --> 00:19:25,640
It's been around for a long time and I use it every day and we'll do that in the next lecture.
