Example #1
0
function extra_contact_form_submit()
{
    $error = false;
    if (!isset($_POST['action']) || 'extra_contact_form_submit' != $_POST['action']) {
        return array();
    }
    if (!isset($_POST['nonce_extra_contact_form']) || !wp_verify_nonce($_POST['nonce_extra_contact_form'], 'extra-contact-form')) {
        $message = array('message' => __('Form submission error, please refresh and try again.', 'extra'), 'type' => 'error');
        $error = true;
    }
    if (empty($_POST['contact_name'])) {
        $message = array('message' => __('Name field cannot be empty.', 'extra'), 'type' => 'error');
        $error = true;
    }
    if (empty($_POST['contact_email'])) {
        $message = array('message' => __('Email field cannot be empty.', 'extra'), 'type' => 'error');
        $error = true;
    }
    if (!is_email($_POST['contact_email'])) {
        $message = array('message' => __('Please enter a valid email address.', 'extra'), 'type' => 'error');
        $error = true;
    }
    if (!$error) {
        $contact_page_options = extra_get_contact_page_options();
        $name = stripslashes(sanitize_text_field($_POST['contact_name']));
        $email = sanitize_email($_POST['contact_email']);
        $email_to = get_site_option('admin_email');
        $email_to = apply_filters('extra_contact_page_email_to', $email_to);
        $subject = sprintf(__('New Message From %1$s%2$s', 'extra'), sanitize_text_field(get_option('blogname')), '' !== $contact_page_options['title'] ? sprintf(_x(' - %s', 'contact form title separator', 'extra'), sanitize_text_field($contact_page_options['title'])) : '');
        $message = stripslashes(wp_strip_all_tags($_POST['contact_message']));
        $headers = 'From: ' . $name . ' <' . $email . '>' . "\r\n";
        $headers .= 'Reply-To: ' . $name . ' <' . $email . '>';
        apply_filters('et_contact_page_headers', $headers, $name, $email);
        wp_mail($email_to, $subject, $message, $headers);
        $message = array('message' => __('Thanks for contacting us.', 'extra'), 'type' => 'success');
    }
    if (empty($message)) {
        $message = array('message' => __('There was a problem, please try again.', 'extra'), 'type' => 'error');
    }
    return $message;
}
						<h2><?php 
        the_title();
        ?>
</h2>

						<?php 
        the_content();
        ?>
						<?php 
        if (!extra_is_builder_built()) {
            wp_link_pages(array('before' => '<div class="page-links">' . __('Pages:', 'extra'), 'after' => '</div>'));
        }
        ?>

						<?php 
        $contact_page_options = extra_get_contact_page_options();
        ?>

						<?php 
        if (!empty($contact_page_options['map_lat']) && !empty($contact_page_options['map_lng'])) {
            ?>
						<div class="contact-map" data-zoom="<?php 
            echo esc_attr($contact_page_options['map_zoom']);
            ?>
" data-lat="<?php 
            echo esc_attr($contact_page_options['map_lat']);
            ?>
" data-lng="<?php 
            echo esc_attr($contact_page_options['map_lng']);
            ?>
"></div>