-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtemplate-my-custom-contact.php
More file actions
65 lines (55 loc) · 2.29 KB
/
template-my-custom-contact.php
File metadata and controls
65 lines (55 loc) · 2.29 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/*
Template Name: Contactformulier
*/
$context = Timber::context();
$context['post'] = Timber::get_post();
$context['nonce'] = wp_nonce_field('#body', 'site_nonce', true, false);
$template = ['page-contact.twig'];
$emailSent = false;
if (!empty($_POST)) {
if (isset($_POST['submitted'])) {
if (!isset($_POST['site_nonce']) || !wp_verify_nonce($_POST['site_nonce'], '#body')) {
print 'Sorry, your nonce did not verify.';
exit;
} else {
//
if (trim($_POST['contact_name']) === '') {
$context['contact_name_error'] = true;
$hasError = true;
} else {
$contact_name = trim($_POST['contact_name']);
$context['contact_name'] = $contact_name;
}
//
if (trim($_POST['contact_contact']) === '') {
$context['contact_contact_error'] = true;
$hasError = true;
} else {
$contact_contact = trim($_POST['contact_contact']);
$context['contact_contact'] = $contact_contact;
}
//
if (!trim($_POST['contact_info']) == '') {
if (function_exists('stripslashes')) {
$contact_info = stripslashes(trim($_POST['contact_info']));
} else {
$contact_info = trim($_POST['contact_info']);
}
}
if (!isset($hasError)) {
$emailTo = get_option('tz_email');
if (!isset($emailTo) || ($emailTo == '')) {
$emailTo = get_option('admin_email');
}
$subject = 'Contactformulier verzonden door ' . $contact_name;
$body = "Naam: $contact_name \nE-mailadres: $contact_contact \nBericht: $contact_info";
$headers = 'From: ' . $contact_name;
wp_mail('wout@woutmager.nl', $subject, $body);
$context['email_sent'] = true;
$emailSent = true;
}
}
}
}
Timber::render($template, $context);