function handle_formnewsletter_ajax() { global $copernico_opt; $fields = ['email-newsletter' => ['name' => __('Email', 'copernico'), 'validate' => function ($value) { if (is_email($value)) { return false; } return __('Enter a valid address!', 'copernico'); }], 'privacy-newsletter' => ['name' => __('Privacy', 'copernico'), 'validate' => function ($value) { if ($value) { return false; } return __('You must accept the conditions!', 'copernico'); }]]; if ($copernico_opt['form_newsletter_recaptcha']) { $fields['g-recaptcha-response'] = ['name' => __('I\'m not a robot', 'copernico')]; } $data = []; foreach ($fields as $field => $fieldData) { $data[$field] = isset($_POST[$field]) ? esc_html($_POST[$field]) : false; if (isset($fieldData['validate'])) { $validate = $fieldData['validate']($data[$field]); if ($validate) { wp_send_json_error($validate); } } elseif (empty($data[$field])) { wp_send_json_error(__('Please, fill the field', 'copernico') . ' ' . $fieldData['name']); } } if ($copernico_opt['form_newsletter_recaptcha']) { // Validare $data['recaptcha'] $response = wp_remote_post('https://www.google.com/recaptcha/api/siteverify', ['body' => ['secret' => $copernico_opt['form_newsletter_recaptcha_secretkey'], 'response' => $data['g-recaptcha-response']]]); $recaptchaError = __('Verify that the Google reCAPTCHA has been verified properly.', 'copernico'); if (is_wp_error($response)) { wp_send_json_error($recaptchaError); } $response = @json_decode(@$response['body']); if (!isset($response->success) || !$response->success) { wp_send_json_error($recaptchaError); } } addToNewsletter($data['email-newsletter']); $return = __('Thank you for your subscription!', 'copernico'); wp_send_json_success($return); }
function handle_formar_ajax() { global $copernico_opt; $fields = ['name-ar' => ['name' => __('Name', 'copernico')], 'email-ar' => ['name' => __('Email', 'copernico'), 'validate' => function ($value) { if (is_email($value)) { return false; } return __('Enter a valid address!', 'copernico'); }], 'telephone-ar' => ['name' => __('Telephone', 'copernico')], 'arrival-ar' => ['name' => __('Arrival date', 'copernico')], 'departure-ar' => ['name' => __('Departure date', 'copernico')], 'adults-ar' => ['name' => __('Adults', 'copernico')], 'childrens-ar' => ['name' => __('Childrens', 'copernico'), 'validate' => function () { return false; }], 'first-child-ar' => ['name' => __('First child age', 'copernico'), 'validate' => function () { return false; }], 'second-child-ar' => ['name' => __('Second child age', 'copernico'), 'validate' => function () { return false; }], 'third-child-ar' => ['name' => __('Third child age', 'copernico'), 'validate' => function () { return false; }], 'fourth-child-ar' => ['name' => __('Fourth child age', 'copernico'), 'validate' => function () { return false; }], 'message-ar' => ['name' => __('Message', 'copernico'), 'validate' => function () { return false; }], 'privacy-ar' => ['name' => __('Privacy', 'copernico'), 'validate' => function ($value) { if ($value) { return false; } return __('You must accept the conditions!', 'copernico'); }]]; if ($copernico_opt['form_ar_recaptcha']) { $fields['g-recaptcha-response'] = ['name' => __('I\'m not a robot', 'copernico')]; } if ($copernico_opt['form_ar_newsletter']) { $fields['newsletter-ar'] = ['name' => __('Newsletter Subscriber', 'copernico'), 'validate' => function ($value) { return false; }]; } if ($copernico_opt['form_ar_tratt']) { $fields['treatment-ar'] = ['name' => __('Treatments', 'copernico'), 'validate' => function ($value) { return false; }]; } $data = []; foreach ($fields as $field => $fieldData) { $data[$field] = isset($_POST[$field]) ? esc_html($_POST[$field]) : false; if (isset($fieldData['validate'])) { $validate = $fieldData['validate']($data[$field]); if ($validate) { wp_send_json_error($validate); } } elseif (empty($data[$field])) { wp_send_json_error(__('Please, fill the field', 'copernico') . ' ' . $fieldData['name']); } } if ($data['newsletter-ar'] == true) { addToNewsletter($data['email-ar'], $data['name-ar']); } if ($copernico_opt['form_ar_recaptcha']) { // Validare $data['recaptcha'] $response = wp_remote_post('https://www.google.com/recaptcha/api/siteverify', ['body' => ['secret' => $copernico_opt['form_ar_recaptcha_secretkey'], 'response' => $data['g-recaptcha-response']]]); $recaptchaError = __('Verify that the Google reCAPTCHA has been verified properly.', 'copernico'); if (is_wp_error($response)) { wp_send_json_error($recaptchaError); } $response = @json_decode(@$response['body']); if (!isset($response->success) || !$response->success) { wp_send_json_error($recaptchaError); } } //$headers = ['Content-Type: text/html; charset=UTF-8']; $name = $data['name-ar']; $email = $data['email-ar']; $message = $data['message-ar']; $telephone = $data['telephone-ar']; if (isset($data['treatment-ar'])) { $treatment = $data['treatment-ar']; } $arrival = $data['arrival-ar']; $departure = $data['departure-ar']; $adults = $data['adults-ar']; $childrens = $data['childrens-ar']; $first_children = $data['first-child-ar']; $second_children = $data['second-child-ar']; $third_children = $data['third-child-ar']; $fourth_children = $data['fourth-child-ar']; if (function_exists('get_field') && get_field('email_hotel_di_inoltro', 'option')) { $email_sender = get_field('email_hotel_di_inoltro', 'option'); } else { $email_sender = get_option('admin_email'); } $custom_message = __('request from', 'copernico') . ' ' . get_bloginfo('name'); $headers[] = "From: {$name} {$custom_message} <{$email_sender}>"; $headers[] = "Reply-To: {$name} <{$email}>"; $nn = "\n\n"; $content = __('Telephone', 'copernico') . ': ' . $telephone . $nn; if ($treatment) { $content .= __('Treatment', 'copernico') . ': ' . $treatment . $nn; } $content .= __('Name', 'copernico') . ': ' . $name . $nn; $content .= __('Email', 'copernico') . ': ' . $email . $nn; $content .= __('Arrival date', 'copernico') . ': ' . $arrival . $nn; $content .= __('Departure date', 'copernico') . ': ' . $departure . $nn; $content .= __('Adults', 'copernico') . ': ' . $adults . $nn; $content .= __('Childrens', 'copernico') . ': ' . $childrens . $nn; $content .= __('First child age', 'copernico') . ': ' . $first_children . $nn; $content .= __('Second child age', 'copernico') . ': ' . $second_children . $nn; $content .= __('Third child age', 'copernico') . ': ' . $third_children . $nn; $content .= __('Fourth child age', 'copernico') . ': ' . $fourth_children . $nn; $content .= __('Message', 'copernico') . ': ' . $message; $body = $content; // insert here the email address (default admin email) $admin_email = get_option('admin_email'); $object = __('Availability Request', 'copernico'); wp_mail($admin_email, $object, $body, $headers); $return = __('Your request successfully sent!', 'copernico'); wp_send_json_success($return); }
function handle_formcontacts_ajax() { global $copernico_opt; $fields = ['name-contacts' => ['name' => __('Name', 'copernico')], 'email-contacts' => ['name' => __('Email', 'copernico'), 'validate' => function ($value) { if (is_email($value)) { return false; } return __('Enter a valid address!', 'copernico'); }], 'message-contacts' => ['name' => __('Message', 'copernico'), 'validate' => function ($value) { if (!empty($value)) { return false; } return __('Insert your message', 'copernico'); }], 'privacy-contacts' => ['name' => __('Privacy', 'copernico'), 'validate' => function ($value) { if ($value) { return false; } return __('You must accept the conditions!', 'copernico'); }]]; // For offers if (isset($_POST['title-contacts'])) { $fields['title-contacts'] = ['name' => __('Title', 'copernico')]; } // For reCAPTCHA if ($copernico_opt['form_contacts_recaptcha']) { $fields['g-recaptcha-response'] = ['name' => __('I\'m not a robot', 'copernico')]; } // For Newsletter if ($copernico_opt['form_contacts_newsletter']) { $fields['newsletter-contacts'] = ['name' => __('Newsletter Subscriber', 'copernico'), 'validate' => function ($value) { return false; }]; } $data = []; foreach ($fields as $field => $fieldData) { $data[$field] = isset($_POST[$field]) ? esc_html($_POST[$field]) : false; if (isset($fieldData['validate'])) { $validate = $fieldData['validate']($data[$field]); if ($validate) { wp_send_json_error($validate); } } elseif (empty($data[$field])) { wp_send_json_error(__('Please, fill the field', 'copernico') . ' ' . $fieldData['name']); } } if ($data['newsletter-contacts'] == true) { addToNewsletter($data['email-contacts'], $data['name-contacts']); } if ($copernico_opt['form_contacts_recaptcha']) { // Validare $data['recaptcha'] $response = wp_remote_post('https://www.google.com/recaptcha/api/siteverify', ['body' => ['secret' => $copernico_opt['form_contacts_recaptcha_secretkey'], 'response' => $data['g-recaptcha-response']]]); $recaptchaError = __('Verify that the Google reCAPTCHA has been verified properly.', 'copernico'); if (is_wp_error($response)) { wp_send_json_error($recaptchaError); } $response = @json_decode(@$response['body']); if (!isset($response->success) || !$response->success) { wp_send_json_error($recaptchaError); } } //$headers = ['Content-Type: text/html; charset=UTF-8']; if (isset($data['title-contacts'])) { $title = $data['title-contacts']; } $name = $data['name-contacts']; $email = $data['email-contacts']; $message = $data['message-contacts']; if (function_exists('get_field') && get_field('email_hotel_di_inoltro', 'option')) { $email_sender = get_field('email_hotel_di_inoltro', 'option'); } else { $email_sender = get_option('admin_email'); } $custom_message = __('from', 'copernico') . ' ' . get_bloginfo('name'); $headers[] = "From: {$name} {$custom_message} <{$email_sender}>"; $headers[] = "Reply-To: {$name} <{$email}>"; $nn = "\n\n"; $content = __('Name', 'copernico') . ': ' . $name . $nn; $content .= __('Email', 'copernico') . ': ' . $email . $nn; $content .= __('Message', 'copernico') . ': ' . $message . $nn; $body = $content; // insert here the email address (default admin email) $admin_email = get_option('admin_email'); if ($title) { $object = __('Request for', 'copernico') . ': ' . $title; } else { $object = __('Request', 'copernico'); } wp_mail($admin_email, $object, $body, $headers); $return = __('Your request successfully sent!', 'copernico'); wp_send_json_success($return); }