return $result;
}
+
// Check that important fields are present
if (empty($_POST['_formID']) || empty($_POST['_recipient']) || empty($_POST['_verification'])) {
$result['message'] = 'Error: missing form configuration data';
return $result;
}
+ // Check captcha if enabled
+ $recaptcha = ['toysrus-2020' => '6LfXYeEZAAAAABhZuPNOCTYgcW5svieZKPYBrOYb'];
+ if (isset($recaptcha[$_POST['_formID']])) {
+ $url = 'https://www.google.com/recaptcha/api/siteverify';
+ $data = array(
+ 'secret' => $recaptcha[$_POST['_formID']],
+ 'response' => $_POST["g-recaptcha-response"]
+ );
+ $options = array(
+ 'http' => array(
+ 'method' => 'POST',
+ 'content' => http_build_query($data)
+ )
+ );
+ $context = stream_context_create($options);
+ $verify = file_get_contents($url, false, $context);
+ $captcha_success = json_decode($verify);
+ if ($captcha_success->success === false) {
+ $result['message'] = 'Error: catcha failed';
+ return $result;
+ }
+ }
+
// If we get to here, the form can be processed and the email sent.
// First, build the email body
$content = buildEmail($_POST);
'organization' => ['fr' => 'Organization', 'en' => 'Organization'],
'best_time_to_contact' => ['fr' => 'Heure de contact préférée', 'en' => 'Best time to contact'],
'more_info' => ['fr' => 'Plus d\'information', 'en' => 'More info'],
+ 'product_1' => ['fr' => 'Produit 1', 'en' => 'Product 1'],
+ 'product_2' => ['fr' => 'Produit 2', 'en' => 'Product 2'],
+ 'product_3' => ['fr' => 'Produit 3', 'en' => 'Product 3'],
+ 'subscribe' => ['fr' => 'Inscription', 'en' => 'Subscribe'],
];
$locale = $data['_locale'] ?? 'en';