WEBVTT 0 00:00.240 --> 00:00.570 All right. 1 00:00.570 --> 00:03.950 So this was a slightly more difficult challenge 2 00:04.130 --> 00:05.670 and let's see if you got it right. 3 00:06.870 --> 00:13.530 Now inside our compose.ejs where we've got our input and our button, in order for us to be able 4 00:13.550 --> 00:20.440 to pass the value inside our input over to our server where we can log it 5 00:20.520 --> 00:27.930 we have to include this inside an HTML form so let's add that now. And our input in our button needs 6 00:27.930 --> 00:35.800 to go inside the form. And we have to make sure that the button is of type submit so that when you click 7 00:35.800 --> 00:43.070 it it actually submits the data that's inside the form to which ever action is specified here. 8 00:43.390 --> 00:49.960 Now we need to change this to a route that we're going to handle and I'm going to call it / 9 00:50.200 --> 00:51.070 compose. 10 00:51.220 --> 00:56.590 So we handle a post request to the /compose route in our server. 11 00:56.950 --> 01:01.930 Now the other thing you have to be careful about is your input has to have a name 12 01:02.080 --> 01:07.200 and this is going to be like the variable name to allow us to tap into its value. 13 01:07.360 --> 01:12.700 So I'm going to call this the postTitle because that's what we're going to use this input for a little 14 01:12.700 --> 01:14.390 bit later on. If you called it 15 01:14.410 --> 01:18.140 anything else that's completely fine as long as you know what it's called 16 01:18.310 --> 01:22.000 and you know what it refers to then it won't be a problem. 17 01:22.030 --> 01:24.900 So now that we're done with our compose. 18 01:24.940 --> 01:31.780 ejs, we're going to have to go into our server and handle what should happen when the page is making 19 01:31.780 --> 01:35.460 a post requests to the compose route. 20 01:35.470 --> 01:40.980 Currently all we have is a get method for our compose route. 21 01:41.050 --> 01:46.420 So our server knows what to do when somebody makes a get request to /compose namely when 22 01:46.420 --> 01:51.520 they try to view it but the server doesn't yet know what to do when somebody makes a post request to 23 01:51.520 --> 01:52.120 that route. 24 01:52.390 --> 02:01.420 So we have to add our app.post method targeting the /compose method and then we add our anonymous 25 02:01.420 --> 02:08.930 function req and res and then we open up a set of curly braces. Inside 26 02:08.930 --> 02:16.420 here is where we'll be able to console log the value of the text that was entered into the input over 27 02:16.430 --> 02:17.040 here. 28 02:17.300 --> 02:22.500 Now just to remind ourselves, that input had a name of postTitle. 29 02:22.700 --> 02:27.080 So I need to tap into that inside this route to be able to log it. 30 02:27.620 --> 02:37.200 And in order to get hold of it I need to use the request.body and this comes from our body-parser 31 02:37.200 --> 02:39.210 module up here. 32 02:39.770 --> 02:48.620 So the usual way that we tap into the post request data is we say request.body. the name of the 33 02:48.620 --> 02:52.990 input which I happened to call postTitle. 34 02:53.190 --> 03:00.760 Now if we can log the post requests that was sent to /compose and we tap into the body 35 03:00.790 --> 03:05.710 using body-parser and the value of the variable could postTitle 36 03:05.710 --> 03:12.790 then once we run this page and refresh it then we should be up to type in some sort of text, hit publish 37 03:13.270 --> 03:17.800 and head over to our console and see it printed in here. 38 03:18.040 --> 03:25.840 So how did you get on with that challenge? If it was ok then go ahead and continue to the next challenge. 39 03:26.290 --> 03:32.200 If it was really difficult or you needed to see all the hints try and review the relevant parts of the 40 03:32.200 --> 03:33.300 EJS module 41 03:33.340 --> 03:35.340 where we went through all of this in detail.