function wpcf7_ajax_json_echo()
{
    if ('POST' != $_SERVER['REQUEST_METHOD'] || !isset($_POST['_wpcf7_is_ajax_call'])) {
        return;
    }
    $echo = '';
    if (isset($_POST['_wpcf7'])) {
        $id = (int) $_POST['_wpcf7'];
        $unit_tag = wpcf7_sanitize_unit_tag($_POST['_wpcf7_unit_tag']);
        if ($contact_form = wpcf7_contact_form($id)) {
            WPCF7_ContactForm::set_current($contact_form);
            $items = array('mailSent' => false, 'into' => '#' . $unit_tag, 'captcha' => null);
            $result = $contact_form->submit(true);
            if (!empty($result['message'])) {
                $items['message'] = $result['message'];
            }
            if ($result['mail_sent']) {
                $items['mailSent'] = true;
            }
            if (!$result['valid']) {
                $invalids = array();
                foreach ($result['invalid_reasons'] as $name => $reason) {
                    $invalid = array('into' => 'span.wpcf7-form-control-wrap.' . sanitize_html_class($name), 'message' => $reason);
                    if (isset($result['invalid_fields'][$name]) && wpcf7_is_name($result['invalid_fields'][$name])) {
                        $invalid['idref'] = $result['invalid_fields'][$name];
                    }
                    $invalids[] = $invalid;
                }
                $items['invalids'] = $invalids;
            }
            if ($result['spam']) {
                $items['spam'] = true;
            }
            if (!empty($result['scripts_on_sent_ok'])) {
                $items['onSentOk'] = $result['scripts_on_sent_ok'];
            }
            if (!empty($result['scripts_on_submit'])) {
                $items['onSubmit'] = $result['scripts_on_submit'];
            }
            $items = apply_filters('wpcf7_ajax_json_echo', $items, $result);
            WPCF7_ContactForm::reset_current();
        }
    }
    $echo = json_encode($items);
    if (wpcf7_is_xhr()) {
        @header('Content-Type: application/json; charset=' . get_option('blog_charset'));
        echo $echo;
    } else {
        @header('Content-Type: text/html; charset=' . get_option('blog_charset'));
        echo '<textarea>' . $echo . '</textarea>';
    }
    exit;
}
function wpcf7_ajax_json_echo()
{
    $echo = '';
    if (isset($_POST['_wpcf7'])) {
        $id = (int) $_POST['_wpcf7'];
        $unit_tag = wpcf7_sanitize_unit_tag($_POST['_wpcf7_unit_tag']);
        if ($contact_form = wpcf7_contact_form($id)) {
            $items = array('mailSent' => false, 'into' => '#' . $unit_tag, 'captcha' => null);
            $result = $contact_form->submit(true);
            if (!empty($result['message'])) {
                $items['message'] = $result['message'];
            }
            if ('mail_sent' == $result['status']) {
                $items['mailSent'] = true;
            }
            if ('validation_failed' == $result['status']) {
                $invalids = array();
                foreach ($result['invalid_fields'] as $name => $field) {
                    $invalids[] = array('into' => 'span.wpcf7-form-control-wrap.' . sanitize_html_class($name), 'message' => $field['reason'], 'idref' => $field['idref']);
                }
                $items['invalids'] = $invalids;
            }
            if ('spam' == $result['status']) {
                $items['spam'] = true;
            }
            if (!empty($result['scripts_on_sent_ok'])) {
                $items['onSentOk'] = $result['scripts_on_sent_ok'];
            }
            if (!empty($result['scripts_on_submit'])) {
                $items['onSubmit'] = $result['scripts_on_submit'];
            }
            $items = apply_filters('wpcf7_ajax_json_echo', $items, $result);
        }
    }
    $echo = json_encode($items);
    if (wpcf7_is_xhr()) {
        @header('Content-Type: application/json; charset=' . get_option('blog_charset'));
        echo $echo;
    } else {
        @header('Content-Type: text/html; charset=' . get_option('blog_charset'));
        echo '<textarea>' . $echo . '</textarea>';
    }
    exit;
}