1 00:00:00,560 --> 00:00:02,880 When we view our site in a browser, and 2 00:00:02,880 --> 00:00:07,840 navigate to the Contact page, the highlight on our navigation changes. 3 00:00:07,840 --> 00:00:10,940 But it still shows our About content. 4 00:00:10,940 --> 00:00:14,436 Let's take a look at our routes.php file. 5 00:00:14,436 --> 00:00:16,970 The first parameter of our git method 6 00:00:16,970 --> 00:00:21,150 has the name variable surrounded by square brackets. 7 00:00:21,150 --> 00:00:24,480 This means, that the argument is optional, so 8 00:00:24,480 --> 00:00:27,930 this route will match with or without the contact. 9 00:00:29,090 --> 00:00:32,340 I want to set up a new route for my contact page. 10 00:00:32,340 --> 00:00:34,961 So I'm going to start by duplicating this route. 11 00:00:38,634 --> 00:00:42,770 I need my contact route to come before the about route. 12 00:00:42,770 --> 00:00:46,870 Since we saw that the about route with also match contact. 13 00:00:46,870 --> 00:00:52,449 Let's change the first parameter to be /contact. 14 00:00:56,245 --> 00:01:00,935 Then I'm going to remove the logger, and 15 00:01:00,935 --> 00:01:04,693 change about to contact-form. 16 00:01:07,417 --> 00:01:11,230 Now when I visit contact in the browser, I see the form. 17 00:01:11,230 --> 00:01:17,230 If I try to submit the contact form, it gives me an error, method not allowed. 18 00:01:17,230 --> 00:01:21,720 The only method allowed is get, let's add a post method. 19 00:01:23,220 --> 00:01:26,927 I'm going to copy my contact route and then change the method. 20 00:01:31,715 --> 00:01:33,790 Instead of get, I'm going use post. 21 00:01:36,680 --> 00:01:40,590 Now when I post the form, I see the contact page again. 22 00:01:41,610 --> 00:01:46,410 When I fill out the form, nothing new happens. 23 00:01:46,410 --> 00:01:49,010 I go back to a blank form. 24 00:01:49,010 --> 00:01:53,000 The first thing I want to do, is have the form save my values. 25 00:01:54,320 --> 00:02:01,500 If I open the contact-form.phtml, I can see that my values here 26 00:02:01,500 --> 00:02:06,200 are set to use the name, email and message variables. 27 00:02:07,280 --> 00:02:10,426 I just need to tell my view about those variables. 28 00:02:12,109 --> 00:02:19,430 In my routes file, we can see that the third parameter is the args array. 29 00:02:19,430 --> 00:02:23,591 I need to get my post values into my args array. 30 00:02:26,611 --> 00:02:29,227 The post details are stored in request. 31 00:02:32,957 --> 00:02:33,570 GetParsedBody. 32 00:02:36,290 --> 00:02:41,470 So I need to merge this array with any other args passed into this route. 33 00:02:42,640 --> 00:02:47,943 args = array merge (args). 34 00:02:51,220 --> 00:02:52,310 And my parse body. 35 00:02:57,774 --> 00:03:01,930 Now when I post the form, I keep any values I may have entered. 36 00:03:02,960 --> 00:03:05,490 Next, I'm going to do some simple validation. 37 00:03:07,960 --> 00:03:12,860 If the name and email and message are set. 38 00:03:12,860 --> 00:03:16,224 I want to log the details, and show the thank you page. 39 00:03:16,224 --> 00:03:24,595 So, if not, (!empty($args, [name]). 40 00:03:29,115 --> 00:03:35,419 And not empty ($args [email]), 41 00:03:35,419 --> 00:03:41,334 and not empty ($args [msg]). 42 00:03:44,257 --> 00:03:51,508 I'm going to log these details as json, so $mail = json_encode, 43 00:03:53,724 --> 00:04:01,257 ($args['name']), $args['email']. 44 00:04:03,422 --> 00:04:07,191 And args msg. 45 00:04:09,761 --> 00:04:12,591 Next, I'll copy the logger from our first route. 46 00:04:19,218 --> 00:04:21,610 I'll change info to notice. 47 00:04:23,220 --> 00:04:26,527 And then I'll pass the json_encoded mail variable. 48 00:04:29,343 --> 00:04:34,608 Now I'm ready to show the thank you page, 49 00:04:34,608 --> 00:04:41,231 return $this-> view-> render($response, 50 00:04:41,231 --> 00:04:46,510 'thankyou.phtml' and the $args). 51 00:04:48,320 --> 00:04:50,242 Let's fill out the form and submit. 52 00:04:53,376 --> 00:04:55,997 My Message. 53 00:04:55,997 --> 00:04:59,079 Now we see a thank you message, and let's check our logs. 54 00:05:05,373 --> 00:05:07,942 Okay, our message is logged as a notice. 55 00:05:10,747 --> 00:05:13,429 You probably won't just log your emails, but 56 00:05:13,429 --> 00:05:18,550 since Emerson isn't checking emails anyway, it doesn't really matter. 57 00:05:18,550 --> 00:05:22,110 You can always set up a mailer dependency to send mail. 58 00:05:22,110 --> 00:05:24,750 Check the notes for more details. 59 00:05:24,750 --> 00:05:27,200 Let's check out some more routing functionality.