From d79ee71389f9160f4cd82845917c4c41e7fde3f6 Mon Sep 17 00:00:00 2001 From: Thedro Neely Date: Thu, 28 Mar 2019 21:24:35 -0400 Subject: app/controllers/contact: Refactor contact controller Use single contact route --- app/controllers/contact.controller.php | 47 ++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'app/controllers') diff --git a/app/controllers/contact.controller.php b/app/controllers/contact.controller.php index 60f5f08..803a67c 100644 --- a/app/controllers/contact.controller.php +++ b/app/controllers/contact.controller.php @@ -1,3 +1,50 @@ name = $name = $_POST['26471'] ?? null; + $form->email = $email = $_POST['26472'] ?? null; + $form->message = $message = $_POST['26478'] ?? null; + $form->spam = $spam = $_POST['agree'] ?? false; + + if ($form->isEmpty()) { + include '../app/views/contact.view.php'; + return; + } + + if ($form->isSpam()) { + error_log('Contact Form Spam: Error 403'); + return http_response_code(403); + } + + if ($form->isEmailValid() === false) { + $emailError = 'Invalid email: ' . "\r" . ''. $email . ''; + include '../app/views/contact.view.php'; + return; + } + + $formSuccess = true; + + $name = null; + $email = null; + $message = null; + $spam = false; + + include '../app/views/contact.view.php'; + fastcgi_finish_request(); + + $contact['database']->insert( + 'contactform', [ + 'name' => $form->name, + 'email' => $form->email, + 'message' => $form->message, + ] + ); + + $form->isSubmit(); + return; +} + require '../app/views/contact.view.php'; -- cgit v1.2.3