1 00:00:00,815 --> 00:00:04,584 We can close base and home. 2 00:00:04,584 --> 00:00:10,669 We're going to add a form tag, we're gonna set the method = post. 3 00:00:10,669 --> 00:00:13,713 And we'll let it submit back here for now. 4 00:00:13,713 --> 00:00:17,445 Form, and we'll add our submit button. 5 00:00:21,962 --> 00:00:29,427 Submit, class= btn btn-primary, 6 00:00:29,427 --> 00:00:35,963 and then Send Message, button. 7 00:00:35,963 --> 00:00:39,307 Okay, before our form, 8 00:00:39,307 --> 00:00:44,095 we're going to import our macros. 9 00:00:44,095 --> 00:00:50,365 So we use a command to import 10 00:00:50,365 --> 00:00:55,826 forms.twig as forms. 11 00:00:55,826 --> 00:00:58,886 This is how we access our macro. 12 00:00:58,886 --> 00:01:04,061 Now within our form, we'll use forms like an object name and 13 00:01:04,061 --> 00:01:06,609 then we'll call them macro. 14 00:01:06,609 --> 00:01:12,055 Forms.input and then we'll pass in name, 15 00:01:12,055 --> 00:01:16,479 we named our file form, not forms. 16 00:01:16,479 --> 00:01:17,671 Let's rename the file. 17 00:01:21,532 --> 00:01:26,886 Great, we have a form that posts to itself, 18 00:01:26,886 --> 00:01:30,521 with a form field named name. 19 00:01:30,521 --> 00:01:33,209 Let's go back and add additional options. 20 00:01:33,209 --> 00:01:40,597 The next argument is a value, we can't use our post variables directly in Twig. 21 00:01:40,597 --> 00:01:44,114 So we'll have to pass those variables into our template. 22 00:01:44,114 --> 00:01:47,811 Let's go into index.php. 23 00:01:47,811 --> 00:01:54,774 And then in our past array, we're going to add a new element called host. 24 00:01:54,774 --> 00:01:59,668 And we'll set this equal to our $_POST values. 25 00:01:59,668 --> 00:02:05,038 Now back in our contact template, we can use for 26 00:02:05,038 --> 00:02:08,938 our next argument, post.name. 27 00:02:08,938 --> 00:02:10,713 Let's try this in the browser again. 28 00:02:14,633 --> 00:02:17,479 Great, our form field keeps the entered data. 29 00:02:17,479 --> 00:02:20,072 The next argument is the type. 30 00:02:20,072 --> 00:02:24,273 I can pass nothing, an empty string, or null, and 31 00:02:24,273 --> 00:02:28,499 they will all default to using that default value. 32 00:02:28,499 --> 00:02:33,490 I can also specify my type as text or anything else I want. 33 00:02:33,490 --> 00:02:36,703 I'm going to pass an empty string. 34 00:02:36,703 --> 00:02:42,832 My final argument is the help, I don't want use anything for name. 35 00:02:42,832 --> 00:02:47,386 So I'm actually just going to leave off these last two arguments. 36 00:02:47,386 --> 00:02:49,960 I'm going to copy this line for email. 37 00:02:53,214 --> 00:02:57,049 My first argument will be email and 38 00:02:57,049 --> 00:03:02,878 then post.email, this time pass an empty string. 39 00:03:02,878 --> 00:03:07,341 And then for help I want to add, 40 00:03:07,341 --> 00:03:13,699 we will never share your email with anyone. 41 00:03:13,699 --> 00:03:15,167 Let's take a look in the browser. 42 00:03:18,442 --> 00:03:21,138 This time, we have a name and an email field. 43 00:03:21,138 --> 00:03:24,733 And our email field shows our message below, 44 00:03:24,733 --> 00:03:28,240 we will never share your email with anyone.