<?php
/* Template Name: Contact */
$context = Timber::get_context();
$post = new TimberPost();
$context['post'] = $post;
$context['image'] = get_field('image', $post->ID);
$context['address'] = get_field('address', $post->ID);
$context['address'] = str_replace(' ', '+', $context['address']);
$context['contact_address'] = get_field('contact_address', $post->ID);
$context['phone_number'] = get_field('phone_number', $post->ID);
$context['email'] = get_field('email', $post->ID);
$context['errors'] = [];
if(isset($_POST['send_contact_mail']) && !empty($_POST['send_contact_mail'])):
if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])):
//your site secret key
$secret = 'secretcaptchakey';
//get verify response data
$verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']);
$responseData = json_decode($verifyResponse);
if($responseData->success):
//contact form submission code
if(empty($_POST['firstName'])){
$context['errors']['firstName'] = 'Vul uw voornaam in';
} else {
$context['form']['firstName'] = $_POST['firstName'];
}
if(empty($_POST['lastName'])){
$context['errors']['lastName'] = 'Vul uw achternaam in';
} else {
$context['form']['lastName'] = $_POST['lastName'];
}
if(empty($_POST['callName'])){
$context['errors']['callName'] = 'Vul uw roepnaam in';
} else {
$context['form']['callName'] = $_POST['callName'];
}
if(empty($_POST['email'])){
$context['errors']['email'] = 'Vul uw email in';
} else {
$context['form']['email'] = $_POST['email'];
}
if(empty($_POST['comment'])){
$context['errors']['comment'] = 'Vul uw opmerking in';
} else {
$context['form']['comment'] = $_POST['comment'];
}
if(count($context['errors']) == 0){
sendTemplateMail('mail/contact_mail_client.twig', $context['form'], 'Uw contactverzoek', $context['form']['email'], '[email protected]');
sendTemplateMail('mail/contact_mail.twig', $context['form'], 'Contactverzoek van '.$context['form']['firstName'].' '.$context['form']['lastName'], '[email protected]', $context['form']['email']);
$context['success'] = 'Uw mail is verstuurd.';
}
endif;
else:
$context['success'] = 'Klik op de Google Recaptcha.';
endif;
else:
$context['success'] = '';
endif;
Timber::render('pages/page-contact.twig', $context );
2.096 views
Hallo, ik ben vandaag voor het eerst Google recaptcha v2 aan het gebruiken. De sitekey/secretkey etc. zijn aangemaakt. Ook doet de captcha het bij het contact formulier. Alleen nu ik de validatie code van mijn contact formulier heb moeten omgooien vanwege de capctcha ontvang ik nu geen mails meer: