aboutsummaryrefslogtreecommitdiff
path: root/app/controllers/contact.controller.php
blob: 8a1a62e33fdccb87d70f791dbc813e16bea969fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php

if ($_SERVER['REQUEST_METHOD'] === 'POST') {

    $form = new Form();

    $form->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->empty()) {
        return http_response_code(403);
    }

    if ($form->spam()) {
        return http_response_code(403);
    }

    if ($form->emailValid() === false) {
        $emailError = 'Invalid email: ' . "\r" . '<b>'. $email . '</b>';
        return include '../app/views/contact.view.php';
    }

    $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,
        ]
    );

    return $form->submit();
}

require '../app/views/contact.view.php';