1
00:00:05,400 --> 00:00:07,370
Welcome back to part two of form fields.

2
00:00:07,500 --> 00:00:11,820
We're going to continue right where we left off last time by heading over to the templates and connecting

3
00:00:11,880 --> 00:00:15,470
our flask form fields to our actual template each html files.

4
00:00:15,600 --> 00:00:16,440
Let's continue.

5
00:00:16,440 --> 00:00:21,240
All right so I have my basic thought py file in my application python file filled out with the forms

6
00:00:21,570 --> 00:00:24,600
as well as views for an index page and a thank you page.

7
00:00:24,600 --> 00:00:28,200
We need to do now is connect these functions to actual templates.

8
00:00:28,200 --> 00:00:30,370
Let's start with our home page for index.

9
00:00:30,420 --> 00:00:36,760
We're going to do here is pretty simple just say welcome to the puppy survey.

10
00:00:36,870 --> 00:00:42,480
So that'll be our header and then we're going to put form form.

11
00:00:42,500 --> 00:00:43,110
There we go.

12
00:00:43,370 --> 00:00:49,580
And we actually don't need a class or action here because we're using W.T. forms.

13
00:00:49,580 --> 00:00:53,090
We're going to start off by inputting the hidden tag for security.

14
00:00:53,270 --> 00:01:02,760
So say for dot the hidden underscore tag and then we're going to set the Breede first we'll say form

15
00:01:02,880 --> 00:01:10,810
dog breed label and then we'll go ahead and say form dog breed and this is the same sort of thing we're

16
00:01:10,810 --> 00:01:15,700
going to do for each field and we're going to add a break statement so that they each show up on a new

17
00:01:15,700 --> 00:01:16,600
line.

18
00:01:16,750 --> 00:01:23,740
So then the next one is going to be form the neutered label and they'll say form dog neutered

19
00:01:26,500 --> 00:01:34,070
and the next one's going to be form and we'll say food choice grabbed the label for that one and then

20
00:01:34,070 --> 00:01:37,580
to us formed dog food choice

21
00:01:40,980 --> 00:01:41,800
at a break.

22
00:01:41,910 --> 00:01:51,470
And let's also put in the mood label so we'll say form that mood that label and then we'll see form

23
00:01:51,720 --> 00:01:56,100
the mood and we'll add another break.

24
00:01:56,100 --> 00:02:00,750
And just a quick note you can always add in text in between any of these fields in your form so I can

25
00:02:00,750 --> 00:02:07,170
say something like any other feedback question mark and then insert form feedback

26
00:02:10,250 --> 00:02:13,480
and we can have a break in between the line.

27
00:02:13,480 --> 00:02:14,250
Any other feedback.

28
00:02:14,260 --> 00:02:16,390
And then the actual feedback text area.

29
00:02:16,660 --> 00:02:18,710
And then finally let's have a submit button.

30
00:02:18,790 --> 00:02:26,470
So say form dog submit open close princes save that and as quick reminder in case you ever want to add

31
00:02:26,470 --> 00:02:28,770
in your own custom classes to any of these.

32
00:02:28,770 --> 00:02:34,720
All you need to do is say form the food choice and then inside of this say class and connected to some

33
00:02:34,720 --> 00:02:36,120
CSSA class.

34
00:02:36,160 --> 00:02:41,360
In our case we don't really have a thesis file to go along with this so just put it through choice.

35
00:02:41,380 --> 00:02:41,720
All right.

36
00:02:41,770 --> 00:02:43,870
So that's basically all we need for our form.

37
00:02:43,900 --> 00:02:49,390
Just to hit tag and then the labels and the actual attributes that correspond with the form that we

38
00:02:49,390 --> 00:02:50,080
created here.

39
00:02:50,080 --> 00:02:51,120
So we have in full form.

40
00:02:51,330 --> 00:02:56,340
And remember repassing in that form right here after we create an instance of it into our studies to.

41
00:02:56,410 --> 00:02:59,860
Which is why we're able to call it from the html file.

42
00:02:59,860 --> 00:03:06,020
Now let's go to our page and for the thank you page you're going to have a letter saying thank you.

43
00:03:06,020 --> 00:03:08,380
Here is the info you gave us.

44
00:03:10,420 --> 00:03:18,210
And we're going to have an ordered list and we're to start off with the breed and then from our session

45
00:03:18,870 --> 00:03:22,000
we're going to grab the Breede key.

46
00:03:22,050 --> 00:03:28,470
So notice here how if I come back to basic pie form I think Page I'm actually feeding in the session

47
00:03:28,830 --> 00:03:31,710
because we imported session from flask.

48
00:03:31,710 --> 00:03:36,980
We can actually just have the session live for that particular user's session so we don't need to pass

49
00:03:36,980 --> 00:03:37,280
it in.

50
00:03:37,290 --> 00:03:42,920
That's why it's a special object and we can just say session Breede neutered mood food and feedback's

51
00:03:42,920 --> 00:03:44,940
are essentially going to be using all of these.

52
00:03:45,240 --> 00:03:46,430
So let's put them in.

53
00:03:46,620 --> 00:03:54,240
So we'll say Breede past them and then we can also put session and then neutered

54
00:03:57,370 --> 00:03:59,370
and then we can just add in a bunch of list items here.

55
00:03:59,400 --> 00:04:01,370
It's up to you how much you want to label these.

56
00:04:01,660 --> 00:04:03,700
And then we can say mood

57
00:04:07,290 --> 00:04:10,040
session.

58
00:04:10,380 --> 00:04:16,460
So in it's a mood something to note here is or calling mood.

59
00:04:16,680 --> 00:04:21,530
If we come back and look what we're actually saving it's saving the mood data and if we come back up

60
00:04:21,530 --> 00:04:24,810
here that means it's actually saving mood one or two.

61
00:04:24,910 --> 00:04:26,630
It's not saving happy or excited.

62
00:04:26,780 --> 00:04:28,940
So we'll see that play out on the thank you page.

63
00:04:28,940 --> 00:04:29,550
We'll see.

64
00:04:29,550 --> 00:04:33,410
CHRY B.F. and fish instead of what was actually provided.

65
00:04:33,410 --> 00:04:34,570
Chicken beef and fish.

66
00:04:34,610 --> 00:04:38,630
The difference between values and the labels that you're providing in your choices.

67
00:04:38,690 --> 00:04:39,970
Just keep that in mind.

68
00:04:40,490 --> 00:04:45,740
So we have our mood there and then we have a couple of more things to fill out the food that was chosen.

69
00:04:46,160 --> 00:04:51,190
Well say session I will say that's food.

70
00:04:51,440 --> 00:04:58,870
And then the feedback say feedback and then call our session object again and grab the feedback.

71
00:05:00,620 --> 00:05:00,920
All right.

72
00:05:00,980 --> 00:05:06,010
So essentially just reporting back everything that was put into the form.

73
00:05:06,220 --> 00:05:10,090
Let's save this and let's make sure we don't make any errors here by running our code.

74
00:05:10,110 --> 00:05:12,560
So I got to say Python basic about pi.

75
00:05:12,810 --> 00:05:15,060
Enter And let me expand this.

76
00:05:15,060 --> 00:05:17,040
Looks like it's running may have to do a little debugging.

77
00:05:17,040 --> 00:05:17,760
You never know.

78
00:05:17,980 --> 00:05:21,570
Let's run it over here and bring this over.

79
00:05:21,570 --> 00:05:23,700
Looks like my general puppie survey is working.

80
00:05:23,700 --> 00:05:24,650
I'm pretty zoomed in here.

81
00:05:24,660 --> 00:05:25,790
Keep that in mind.

82
00:05:25,830 --> 00:05:26,870
So it says what are you.

83
00:05:26,910 --> 00:05:28,440
I will say I'm a lab.

84
00:05:28,650 --> 00:05:30,350
We'll say the radio box have been neutered.

85
00:05:30,450 --> 00:05:31,320
You get to chicken.

86
00:05:31,320 --> 00:05:35,680
B fish will say fish are happy or excited because they are happy.

87
00:05:35,730 --> 00:05:40,390
And the other feedback you are great let's hit submit.

88
00:05:40,570 --> 00:05:43,160
Make sure that works OK and that is a sink.

89
00:05:43,180 --> 00:05:46,390
Here's the info you gave us and then we have that list Labbe true.

90
00:05:46,460 --> 00:05:49,300
And then here you can notice I have mood underscore one.

91
00:05:49,300 --> 00:05:52,680
Notice how I'm actually saving that value instead of the label.

92
00:05:52,690 --> 00:05:58,180
So if I come back here happy and excited are those labels but mood one is what I'm actually grabbing

93
00:05:58,180 --> 00:05:59,100
and saving to the session.

94
00:05:59,110 --> 00:06:00,870
That's the data that's passed in.

95
00:06:00,910 --> 00:06:06,310
So if I come back to basic that pie again the data is going to be that first item in the tuple mood

96
00:06:06,310 --> 00:06:08,610
one and move to fish here.

97
00:06:08,620 --> 00:06:10,560
You notice it's lower case on our page.

98
00:06:10,590 --> 00:06:11,350
Thank you.

99
00:06:11,350 --> 00:06:15,780
If I select a chicken I should have seen S.H. high and if I had selected beef I would have just seen

100
00:06:15,810 --> 00:06:16,920
B.F..

101
00:06:17,050 --> 00:06:17,630
All right.

102
00:06:17,640 --> 00:06:22,870
And that's the basics of how we can connect the form to those template files and how we can use a session

103
00:06:23,170 --> 00:06:29,180
to actually grab a user's session information as well as saving it in our actual function view.

104
00:06:29,650 --> 00:06:30,340
OK.

105
00:06:30,370 --> 00:06:33,640
Coming up next we're going to continue our discussion about flask forms.

106
00:06:33,640 --> 00:06:34,720
We'll see you at the next lecture.
