Example #1
0
function wpcf7_honeypot_shortcode_handler($tag)
{
    $tag = new WPCF7_Shortcode($tag);
    if (empty($tag->name)) {
        return '';
    }
    $validation_error = wpcf7_get_validation_error($tag->name);
    $class = wpcf7_form_controls_class('text');
    $atts = array();
    $atts['class'] = $tag->get_class_option($class);
    $atts['id'] = $tag->get_option('id', 'id', true);
    $atts['message'] = __('Please leave this field empty.', 'wpcf7_honeypot');
    $atts['name'] = $tag->name;
    $atts['type'] = $tag->type;
    $atts['nomessage'] = $tag->get_option('nomessage');
    $atts['validation_error'] = $validation_error;
    $inputid = !empty($atts['id']) ? 'id="' . $atts['id'] . '" ' : '';
    $html = '<span class="wpcf7-form-control-wrap ' . $atts['name'] . '-wrap" style="display:none !important;visibility:hidden !important;">';
    $html .= '<input ' . $inputid . 'class="' . $atts['class'] . '"  type="text" name="' . $atts['name'] . '" value="" size="40" tabindex="-1" />';
    if (!$atts['nomessage']) {
        $html .= '<span class="hp-message">' . $atts['message'] . '</span>';
    }
    $html .= $validation_error . '</span>';
    // Hook for filtering finished Honeypot form element.
    return apply_filters('wpcf7_honeypot_html_output', $html, $atts);
}
Example #2
0
function wpcf7_date_validation_filter($result, $tag)
{
    $tag = new WPCF7_Shortcode($tag);
    $name = $tag->name;
    $min = $tag->get_date_option('min');
    $max = $tag->get_date_option('max');
    $value = isset($_POST[$name]) ? trim(strtr((string) $_POST[$name], "\n", " ")) : '';
    if ($tag->is_required() && '' == $value) {
        $result['valid'] = false;
        $result['reason'][$name] = wpcf7_get_message('invalid_required');
    } elseif ('' != $value && !wpcf7_is_date($value)) {
        $result['valid'] = false;
        $result['reason'][$name] = wpcf7_get_message('invalid_date');
    } elseif ('' != $value && !empty($min) && $value < $min) {
        $result['valid'] = false;
        $result['reason'][$name] = wpcf7_get_message('date_too_early');
    } elseif ('' != $value && !empty($max) && $max < $value) {
        $result['valid'] = false;
        $result['reason'][$name] = wpcf7_get_message('date_too_late');
    }
    if (isset($result['reason'][$name]) && ($id = $tag->get_id_option())) {
        $result['idref'][$name] = $id;
    }
    return $result;
}
Example #3
0
function wpcf7_number_validation_filter($result, $tag)
{
    $tag = new WPCF7_Shortcode($tag);
    $name = $tag->name;
    $value = isset($_POST[$name]) ? trim(strtr((string) $_POST[$name], "\n", " ")) : '';
    $min = $tag->get_option('min', 'signed_int', true);
    $max = $tag->get_option('max', 'signed_int', true);
    if ($tag->is_required() && '' == $value) {
        $result['valid'] = false;
        $result['reason'][$name] = wpcf7_get_message('invalid_required');
    } elseif ('' != $value && !wpcf7_is_number($value)) {
        $result['valid'] = false;
        $result['reason'][$name] = wpcf7_get_message('invalid_number');
    } elseif ('' != $value && '' != $min && (double) $value < (double) $min) {
        $result['valid'] = false;
        $result['reason'][$name] = wpcf7_get_message('number_too_small');
    } elseif ('' != $value && '' != $max && (double) $max < (double) $value) {
        $result['valid'] = false;
        $result['reason'][$name] = wpcf7_get_message('number_too_large');
    }
    if (isset($result['reason'][$name]) && ($id = $tag->get_id_option())) {
        $result['idref'][$name] = $id;
    }
    return $result;
}
function wpcf7_mathcaptcha_shortcode_handler($tag)
{
    if (!is_user_logged_in() || is_user_logged_in() && !Math_Captcha()->options['general']['hide_for_logged_users']) {
        $tag = new WPCF7_Shortcode($tag);
        if (empty($tag->name)) {
            return '';
        }
        $validation_error = wpcf7_get_validation_error($tag->name);
        $class = wpcf7_form_controls_class($tag->type);
        if ($validation_error) {
            $class .= ' wpcf7-not-valid';
        }
        $atts = array();
        $atts['size'] = 2;
        $atts['maxlength'] = 2;
        $atts['class'] = $tag->get_class_option($class);
        $atts['id'] = $tag->get_option('id', 'id', true);
        $atts['tabindex'] = $tag->get_option('tabindex', 'int', true);
        $atts['aria-required'] = 'true';
        $atts['type'] = 'text';
        $atts['name'] = $tag->name;
        $atts['value'] = '';
        $atts = wpcf7_format_atts($atts);
        $mc_form = Math_Captcha()->core->generate_captcha_phrase('cf7');
        $mc_form[$mc_form['input']] = '<input %2$s />';
        $math_captcha_title = apply_filters('math_captcha_title', Math_Captcha()->options['general']['title']);
        return sprintf((empty($math_captcha_title) ? '' : $math_captcha_title) . '<span class="wpcf7-form-control-wrap %1$s">' . $mc_form[1] . $mc_form[2] . $mc_form[3] . '%3$s</span><input type="hidden" value="' . (Math_Captcha()->core->session_number - 1) . '" name="' . $tag->name . '-sn" />', $tag->name, $atts, $validation_error);
    }
}
Example #5
0
 function wpcf7_icon_btn_shortcode_handler($tag)
 {
     $tag = new WPCF7_Shortcode($tag);
     $class = wpcf7_form_controls_class($tag->type);
     $atts = array();
     $atts['class'] = $tag->get_class_option($class);
     $atts['class'] = $atts['class'] . ' wpcf7-submit';
     //add the default submit class
     $atts['id'] = $tag->get_id_option();
     $atts['tabindex'] = $tag->get_option('tabindex', 'int', true);
     $atts['type'] = 'submit';
     $atts = wpcf7_format_atts($atts);
     //get icon class
     $icon_class = $tag->get_option('icon', '', true);
     $icon_class = empty($icon_class) ? 'fa-send' : $icon_class;
     //add default class if empty
     $icon_class = 'fa ' . esc_attr($icon_class);
     //add fa // did u notice space after fa
     //get button label
     $value = isset($tag->values[0]) ? $tag->values[0] : '';
     if (empty($value)) {
         $value = __('Send', 'contact-form-7');
     }
     //complete string
     $html = sprintf('<button %1$s /><i class="%2$s"></i> %3$s</button>', $atts, $icon_class, esc_html($value));
     return $html;
 }
Example #6
0
function wpcf7_count_shortcode_handler($tag)
{
    $tag = new WPCF7_Shortcode($tag);
    if (empty($tag->name)) {
        return '';
    }
    $target = wpcf7_scan_shortcode(array('name' => $tag->name));
    $maxlength = $minlength = null;
    if ($target) {
        $target = new WPCF7_Shortcode($target[0]);
        $maxlength = $target->get_maxlength_option();
        $minlength = $target->get_minlength_option();
        if ($maxlength && $minlength && $maxlength < $minlength) {
            $maxlength = $minlength = null;
        }
    }
    if ($tag->has_option('down')) {
        $value = (int) $maxlength;
        $class = 'wpcf7-character-count down';
    } else {
        $value = '0';
        $class = 'wpcf7-character-count up';
    }
    $atts = array();
    $atts['id'] = $tag->get_id_option();
    $atts['class'] = $tag->get_class_option($class);
    $atts['data-target-name'] = $tag->name;
    $atts['data-starting-value'] = $value;
    $atts['data-current-value'] = $value;
    $atts['data-maximum-value'] = $maxlength;
    $atts['data-minimum-value'] = $minlength;
    $atts = wpcf7_format_atts($atts);
    $html = sprintf('<span %1$s>%2$s</span>', $atts, $value);
    return $html;
}
function wpcf7_birthday_validation_filter($result, $tag)
{
    $tag = new WPCF7_Shortcode($tag);
    $name = $tag->name;
    $value = isset($_POST[$name]) ? trim(wp_unslash(strtr((string) $_POST[$name], "\n", " "))) : '';
    if ('birthday' == $tag->type && $value != '') {
        if (preg_match('@^(0?[1-9]|[12][0-9]|3[01])/(0?[1-9]|1[0-2])$@', $value) != 1) {
            $result['valid'] = false;
            $result['reason'][$name] = wpcf7_get_message('invalid_birthday');
        }
    }
    if ('birthday*' == $tag->type) {
        if ($value == '') {
            $result['valid'] = false;
            $result['reason'][$name] = wpcf7_get_message('invalid_required');
        } else {
            if (preg_match('@^(0?[1-9]|[12][0-9]|3[01])/(0?[1-9]|1[0-2])$@', $value) != 1) {
                $result['valid'] = false;
                $result['reason'][$name] = wpcf7_get_message('invalid_birthday');
            }
        }
    }
    if (isset($result['reason'][$name]) && ($id = $tag->get_id_option())) {
        $result['idref'][$name] = $id;
    }
    return $result;
}
function cf7bs_file_shortcode_handler($tag)
{
    $tag = new WPCF7_Shortcode($tag);
    if (empty($tag->name)) {
        return '';
    }
    $mode = $status = 'default';
    $validation_error = wpcf7_get_validation_error($tag->name);
    $class = wpcf7_form_controls_class($tag->type);
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
        $status = 'error';
    }
    // size is not used since Bootstrap input fields always scale 100%
    //$atts['size'] = $tag->get_size_option( '40' );
    if ($tag->is_required()) {
        $mode = 'required';
    }
    $value = (string) reset($tag->values);
    $placeholder = '';
    if ($tag->has_option('placeholder') || $tag->has_option('watermark')) {
        $placeholder = $value;
        $value = '';
    } elseif (empty($value)) {
        $value = $tag->get_default_option();
    }
    if (wpcf7_is_posted() && isset($_POST[$tag->name])) {
        $value = stripslashes_deep($_POST[$tag->name]);
    }
    $field = new CF7BS_Form_Field(cf7bs_apply_field_args_filter(array('name' => $tag->name, 'id' => $tag->get_option('id', 'id', true), 'class' => $tag->get_class_option($class), 'type' => 'file', 'value' => '1', 'label' => $tag->content, 'help_text' => $validation_error, 'size' => cf7bs_get_form_property('size'), 'grid_columns' => cf7bs_get_form_property('grid_columns'), 'form_layout' => cf7bs_get_form_property('layout'), 'form_label_width' => cf7bs_get_form_property('label_width'), 'form_breakpoint' => cf7bs_get_form_property('breakpoint'), 'mode' => $mode, 'status' => $status, 'tabindex' => $tag->get_option('tabindex', 'int', true), 'wrapper_class' => $tag->name), $tag->basetype, $tag->name));
    $html = $field->display(false);
    return $html;
}
function cf7bs_captcha_shortcode_handler($tag)
{
    $tag_obj = new WPCF7_Shortcode($tag);
    if ('captchac' == $tag_obj->type && !class_exists('ReallySimpleCaptcha')) {
        return '<em>' . __('To use CAPTCHA, you need <a href="http://wordpress.org/extend/plugins/really-simple-captcha/">Really Simple CAPTCHA</a> plugin installed.', 'bootstrap-for-contact-form-7') . '</em>';
    }
    if (empty($tag_obj->name)) {
        return '';
    }
    $validation_error = wpcf7_get_validation_error($tag_obj->name);
    if ('captchac' == $tag_obj->type) {
        if ($image_sizes_array = preg_grep('%^size:[smlSML]$%', $tag['options'])) {
            $tag['options'] = array_values(array_diff_key($tag['options'], $image_sizes_array));
        }
        $size = cf7bs_get_form_property('size');
        $image_size = 'large' == $size ? 'l' : ('small' == $size ? 's' : 'm');
        $tag['options'][] = 'size:' . $image_size;
        $field = new CF7BS_Form_Field(cf7bs_apply_field_args_filter(array('name' => wpcf7_captcha_shortcode_handler($tag), 'type' => 'custom', 'label' => $tag_obj->content, 'help_text' => $validation_error, 'grid_columns' => cf7bs_get_form_property('grid_columns'), 'form_layout' => cf7bs_get_form_property('layout'), 'form_label_width' => cf7bs_get_form_property('label_width'), 'form_breakpoint' => cf7bs_get_form_property('breakpoint'), 'tabindex' => false, 'wrapper_class' => ''), $tag_obj->basetype, $tag_obj->name));
        $html = $field->display(false);
        return $html;
    } elseif ('captchar' == $tag_obj->type) {
        $mode = $status = 'default';
        $class = wpcf7_form_controls_class($tag_obj->type, 'wpcf7-text');
        if ($validation_error) {
            $class .= ' wpcf7-not-valid';
            $status = 'error';
        }
        // size is not used since Bootstrap input fields always scale 100%
        //$atts['size'] = $tag->get_size_option( '40' );
        $value = (string) reset($tag_obj->values);
        $placeholder = '';
        if (wpcf7_is_posted()) {
            $value = '';
        }
        if ($tag_obj->has_option('placeholder') || $tag_obj->has_option('watermark')) {
            $placeholder = $value;
            $value = '';
        }
        $input_before = $input_after = '';
        if ($tag_obj->has_option('include_captchac') && class_exists('ReallySimpleCaptcha')) {
            $captchac_mode = $tag_obj->get_option('include_captchac', '[A-Za-z]+', true);
            if ($captchac_mode && 'after' == strtolower($captchac_mode)) {
                $captchac_mode = 'input_after';
            } else {
                $captchac_mode = 'input_before';
            }
            $tag = cf7bs_captchar_to_captchac($tag);
            ${$captchac_mode} = wpcf7_captcha_shortcode_handler($tag);
        }
        $field = new CF7BS_Form_Field(cf7bs_apply_field_args_filter(array('name' => $tag_obj->name, 'id' => $tag_obj->get_option('id', 'id', true), 'class' => $tag_obj->get_class_option($class), 'type' => 'text', 'value' => $value, 'placeholder' => $placeholder, 'label' => $tag_obj->content, 'help_text' => $validation_error, 'size' => cf7bs_get_form_property('size'), 'form_layout' => cf7bs_get_form_property('layout'), 'form_label_width' => cf7bs_get_form_property('label_width'), 'form_breakpoint' => cf7bs_get_form_property('breakpoint'), 'mode' => $mode, 'status' => $status, 'maxlength' => $tag_obj->get_maxlength_option(), 'tabindex' => $tag_obj->get_option('tabindex', 'int', true), 'wrapper_class' => $tag_obj->name, 'input_before' => $input_before, 'input_after' => $input_after, 'input_before_class' => 'input-group-addon input-group-has-image', 'input_after_class' => 'input-group-addon input-group-has-image'), $tag_obj->basetype, $tag_obj->name));
        $html = $field->display(false);
        return $html;
    }
    return '';
}
function wpcf7_acceptance_validation_filter($result, $tag)
{
    if (!wpcf7_acceptance_as_validation()) {
        return $result;
    }
    $tag = new WPCF7_Shortcode($tag);
    $name = $tag->name;
    $value = !empty($_POST[$name]) ? 1 : 0;
    $invert = $tag->has_option('invert');
    if ($invert && $value || !$invert && !$value) {
        $result->invalidate($tag, wpcf7_get_message('accept_terms'));
    }
    return $result;
}
Example #11
0
function wpcf7_text_validation_filter($result, $tag)
{
    $tag = new WPCF7_Shortcode($tag);
    $name = $tag->name;
    $value = isset($_POST[$name]) ? trim(wp_unslash(strtr((string) $_POST[$name], "\n", " "))) : '';
    if ('text' == $tag->basetype) {
        if ($tag->is_required() && '' == $value) {
            $result->invalidate($tag, wpcf7_get_message('invalid_required'));
        }
    }
    if ('email' == $tag->basetype) {
        if ($tag->is_required() && '' == $value) {
            $result->invalidate($tag, wpcf7_get_message('invalid_required'));
        } elseif ('' != $value && !wpcf7_is_email($value)) {
            $result->invalidate($tag, wpcf7_get_message('invalid_email'));
        }
    }
    if ('url' == $tag->basetype) {
        if ($tag->is_required() && '' == $value) {
            $result->invalidate($tag, wpcf7_get_message('invalid_required'));
        } elseif ('' != $value && !wpcf7_is_url($value)) {
            $result->invalidate($tag, wpcf7_get_message('invalid_url'));
        }
    }
    if ('tel' == $tag->basetype) {
        if ($tag->is_required() && '' == $value) {
            $result->invalidate($tag, wpcf7_get_message('invalid_required'));
        } elseif ('' != $value && !wpcf7_is_tel($value)) {
            $result->invalidate($tag, wpcf7_get_message('invalid_tel'));
        }
    }
    if (!empty($value)) {
        $maxlength = $tag->get_maxlength_option();
        $minlength = $tag->get_minlength_option();
        if ($maxlength && $minlength && $maxlength < $minlength) {
            $maxlength = $minlength = null;
        }
        $code_units = wpcf7_count_code_units($value);
        if (false !== $code_units) {
            if ($maxlength && $maxlength < $code_units) {
                $result->invalidate($tag, wpcf7_get_message('invalid_too_long'));
            } elseif ($minlength && $code_units < $minlength) {
                $result->invalidate($tag, wpcf7_get_message('invalid_too_short'));
            }
        }
    }
    return $result;
}
function cf7bs_submit_shortcode_handler($tag)
{
    $tag = new WPCF7_Shortcode($tag);
    $class = wpcf7_form_controls_class($tag->type);
    $value = isset($tag->values[0]) ? $tag->values[0] : '';
    if (empty($value)) {
        $value = __('Send', 'contact-form-7');
    }
    $size = cf7bs_get_form_property('submit_size');
    if (!$size) {
        $size = cf7bs_get_form_property('size');
    }
    $button = new CF7BS_Button(array('mode' => 'submit', 'id' => $tag->get_option('id', 'id', true), 'class' => $tag->get_class_option($class), 'title' => $value, 'type' => cf7bs_get_form_property('submit_type'), 'size' => $size, 'tabindex' => $tag->get_option('tabindex', 'int', true), 'align' => $tag->get_option('align', '[A-Za-z]+', true), 'grid_columns' => cf7bs_get_form_property('grid_columns'), 'form_layout' => cf7bs_get_form_property('layout'), 'form_label_width' => cf7bs_get_form_property('label_width'), 'form_breakpoint' => cf7bs_get_form_property('breakpoint')));
    $html = $button->display(false);
    return $html;
}
function wpcf7_custom_textarea_validation_message($result, $tag)
{
    $cmtatag = new WPCF7_Shortcode($tag);
    $type = $cmtatag->type;
    $name = $cmtatag->name;
    $post_id = sanitize_text_field($_POST['_wpcf7']);
    $value = isset($_POST[$name]) ? (string) $_POST[$name] : '';
    $key = "_cf7cm_" . $name;
    $val = get_post_meta($post_id, $key, true);
    $enable = get_post_meta($post_id, '_cf7cm_enable_errors');
    if ($enable[0] != 0) {
        if ($cmtatag->is_required() && '' == $value) {
            $result->invalidate($cmtatag, $val);
        }
        if (!empty($value)) {
            $maxlength = $cmtatag->get_maxlength_option();
            $minlength = $cmtatag->get_minlength_option();
            if ($maxlength && $minlength && $maxlength < $minlength) {
                $maxlength = $minlength = null;
            }
            $code_units = wpcf7_count_code_units($value);
            if (false !== $code_units) {
                if ($maxlength && $maxlength < $code_units) {
                    $result->invalidate($cmtatag, $val);
                } elseif ($minlength && $code_units < $minlength) {
                    $result->invalidate($cmtatag, $val);
                }
            }
        }
    }
    return $result;
}
Example #14
0
function wpcf7_textarea_validation_filter($result, $tag)
{
    $tag = new WPCF7_Shortcode($tag);
    $type = $tag->type;
    $name = $tag->name;
    $value = isset($_POST[$name]) ? (string) $_POST[$name] : '';
    if ('textarea*' == $type) {
        if ('' == $value) {
            $result['valid'] = false;
            $result['reason'][$name] = wpcf7_get_message('invalid_required');
        }
    }
    if (isset($result['reason'][$name]) && ($id = $tag->get_id_option())) {
        $result['idref'][$name] = $id;
    }
    return $result;
}
Example #15
0
function wpcf7_button_shortcode_handler($tag)
{
    $tag = new WPCF7_Shortcode($tag);
    $class = wpcf7_form_controls_class($tag->type);
    $atts = array();
    $atts['class'] = $tag->get_class_option($class);
    $atts['id'] = $tag->get_id_option();
    $atts['tabindex'] = $tag->get_option('tabindex', 'int', true);
    $value = isset($tag->values[0]) ? $tag->values[0] : '';
    if (empty($value)) {
        $value = __('Send', 'contact-form-7');
    }
    $atts['type'] = 'submit';
    $atts = wpcf7_format_atts($atts);
    $html = sprintf('<button %1$s>%2$s</button>', $atts, $value);
    return $html;
}
Example #16
0
function wpcf7_quiz_validation_filter($result, $tag)
{
    $tag = new WPCF7_Shortcode($tag);
    $name = $tag->name;
    $answer = isset($_POST[$name]) ? wpcf7_canonicalize($_POST[$name]) : '';
    $answer = wp_unslash($answer);
    $answer_hash = wp_hash($answer, 'wpcf7_quiz');
    $expected_hash = isset($_POST['_wpcf7_quiz_answer_' . $name]) ? (string) $_POST['_wpcf7_quiz_answer_' . $name] : '';
    if ($answer_hash != $expected_hash) {
        $result['valid'] = false;
        $result['reason'][$name] = wpcf7_get_message('quiz_answer_not_correct');
    }
    if (isset($result['reason'][$name]) && ($id = $tag->get_id_option())) {
        $result['idref'][$name] = $id;
    }
    return $result;
}
Example #17
0
function wpcf7c_back_shortcode_handler($tag)
{
    $tag = new WPCF7_Shortcode($tag);
    $class = wpcf7_form_controls_class($tag->type);
    $atts = array();
    $atts['class'] = $tag->get_class_option($class) . " wpcf7c-elm-step2 wpcf7c-btn-back wpcf7c-force-hide";
    $atts['id'] = $tag->get_option('id', 'id', true);
    $atts['tabindex'] = $tag->get_option('tabindex', 'int', true);
    $value = isset($tag->values[0]) ? $tag->values[0] : '';
    if (empty($value)) {
        $value = __('Backedit', 'contact-form-7-add-confirm');
    }
    $atts['type'] = 'button';
    $atts['value'] = $value;
    $atts = wpcf7_format_atts($atts);
    $html = sprintf('<input %1$s />', $atts);
    return $html;
}
Example #18
0
function wpcf7_acceptance_validation_filter($result, $tag)
{
    if (!wpcf7_acceptance_as_validation()) {
        return $result;
    }
    $tag = new WPCF7_Shortcode($tag);
    $name = $tag->name;
    $value = !empty($_POST[$name]) ? 1 : 0;
    $invert = $tag->has_option('invert');
    if ($invert && $value || !$invert && !$value) {
        $result['valid'] = false;
        $result['reason'][$name] = wpcf7_get_message('accept_terms');
    }
    if (isset($result['reason'][$name]) && ($id = $tag->get_id_option())) {
        $result['idref'][$name] = $id;
    }
    return $result;
}
 function recaptcha_shortcode_handler($tag)
 {
     if (!WP_reCaptcha::instance()->is_required()) {
         return apply_filters('wp_recaptcha_disabled_html', '');
     }
     $tag = new WPCF7_Shortcode($tag);
     if (empty($tag->name)) {
         return '';
     }
     $atts = null;
     if ($theme = $tag->get_option('theme', '', true)) {
         $atts = array('data-theme' => $theme);
     }
     $recaptcha_html = WP_reCaptcha::instance()->recaptcha_html($atts);
     $validation_error = wpcf7_get_validation_error($tag->name);
     $html = sprintf(apply_filters('wp_recaptcha_cf7_shortcode_wrap', '<span class="wpcf7-form-control-wrap %1$s">%2$s %3$s</span>'), $tag->name, $recaptcha_html, $validation_error);
     return $html;
 }
Example #20
0
function wpcf7_submit_shortcode_handler($tag)
{
    $tag = new WPCF7_Shortcode($tag);
    $class = wpcf7_form_controls_class($tag->type);
    $atts = array();
    $atts['class'] = $tag->get_class_option($class);
    $atts['id'] = $tag->get_option('id', 'id', true);
    $atts['tabindex'] = $tag->get_option('tabindex', 'int', true);
    $value = isset($tag->values[0]) ? $tag->values[0] : '';
    if (empty($value)) {
        $value = __('Send', 'wpcf7');
    }
    $atts['type'] = 'submit';
    $atts['value'] = $value;
    $atts = wpcf7_format_atts($atts);
    $html = sprintf('<input %1$s />', $atts);
    return $html;
}
Example #21
0
/**
 * render wpcf7 field for counties
 * @param $tag
 */
function _hw_wcpf7_country_field_shortcode($tag)
{
    if (!is_array($tag)) {
        return '';
    }
    $tag = new WPCF7_Shortcode($tag);
    if (empty($tag->name)) {
        return '';
    }
    $validation_error = wpcf7_get_validation_error($tag->name);
    $class = wpcf7_form_controls_class($tag->type);
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
    }
    $atts = array();
    $atts['class'] = $tag->get_class_option($class);
    $atts['id'] = $tag->get_id_option();
    $atts['tabindex'] = $tag->get_option('tabindex', 'int', true);
    if ($tag->is_required()) {
        $atts['aria-required'] = 'true';
    }
    $atts['aria-invalid'] = $validation_error ? 'true' : 'false';
    $multiple = $tag->has_option('multiple');
    $include_blank = $tag->has_option('include_blank');
    $first_as_label = $tag->has_option('first_as_label');
    //$values = $tag->values;
    $values = array('0' => 'Select country');
    $values = array_merge($values, hw_wpcf7_field_countries_data());
    $labels = $tag->labels;
    $html = '';
    foreach ($values as $key => $value) {
        $item_atts = array('value' => $value);
        $item_atts = wpcf7_format_atts($item_atts);
        $label = isset($labels[$key]) ? $labels[$key] : $value;
        $html .= sprintf('<option %1$s>%2$s</option>', $item_atts, esc_html($label));
    }
    if ($multiple) {
        $atts['multiple'] = 'multiple';
    }
    $atts['name'] = $tag->name . ($multiple ? '[]' : '');
    $atts = wpcf7_format_atts($atts);
    $html = sprintf('<span class="wpcf7-form-control-wrap %1$s"><select %2$s>%3$s</select>%4$s</span>', sanitize_html_class($tag->name), $atts, $html, $validation_error);
    return $html;
}
Example #22
0
function wpcf7_text_validation_filter($result, $tag)
{
    $tag = new WPCF7_Shortcode($tag);
    $name = $tag->name;
    $value = isset($_POST[$name]) ? trim(wp_unslash(strtr((string) $_POST[$name], "\n", " "))) : '';
    if ('text*' == $tag->type) {
        if ('' == $value) {
            $result['valid'] = false;
            $result['reason'][$name] = wpcf7_get_message('invalid_required');
        }
    }
    if ('email' == $tag->basetype) {
        if ($tag->is_required() && '' == $value) {
            $result['valid'] = false;
            $result['reason'][$name] = wpcf7_get_message('invalid_required');
        } elseif ('' != $value && !wpcf7_is_email($value)) {
            $result['valid'] = false;
            $result['reason'][$name] = wpcf7_get_message('invalid_email');
        }
    }
    if ('url' == $tag->basetype) {
        if ($tag->is_required() && '' == $value) {
            $result['valid'] = false;
            $result['reason'][$name] = wpcf7_get_message('invalid_required');
        } elseif ('' != $value && !wpcf7_is_url($value)) {
            $result['valid'] = false;
            $result['reason'][$name] = wpcf7_get_message('invalid_url');
        }
    }
    if ('tel' == $tag->basetype) {
        if ($tag->is_required() && '' == $value) {
            $result['valid'] = false;
            $result['reason'][$name] = wpcf7_get_message('invalid_required');
        } elseif ('' != $value && !wpcf7_is_tel($value)) {
            $result['valid'] = false;
            $result['reason'][$name] = wpcf7_get_message('invalid_tel');
        }
    }
    if (isset($result['reason'][$name]) && ($id = $tag->get_id_option())) {
        $result['idref'][$name] = $id;
    }
    return $result;
}
/**
 * Renders the itens id input control (html code)
 * 
 * @param string $tagName defined by the user at form's edit form (inside 
 *                        shortcode brackets)
 * 
 * @return void
 */
function wpcf7_authoremail_shortcode_handler($tagName)
{
    global $post;
    $tag = new WPCF7_Shortcode($tagName);
    if (empty($tag->name)) {
        return '';
    }
    $class = wpcf7_form_controls_class($tag->type);
    $class .= ' wpcf7-authoremail';
    $author = get_the_author();
    $author_email = get_the_author_meta('user_email');
    $atts = array();
    $atts['class'] = $tag->get_class_option($class);
    $atts['id'] = $tag->get_id_option();
    $atts['type'] = 'hidden';
    $atts['value'] = $author_email;
    $atts['name'] = $tag->name;
    $atts = wpcf7_format_atts($atts);
    $html = sprintf('<input %1$s />', $atts);
    return $html;
}
Example #24
0
function wpcf7_quiz_shortcode_handler($tag)
{
    $tag = new WPCF7_Shortcode($tag);
    if (empty($tag->name)) {
        return '';
    }
    $validation_error = wpcf7_get_validation_error($tag->name);
    $class = wpcf7_form_controls_class($tag->type);
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
    }
    $atts = array();
    $atts['size'] = $tag->get_size_option('40');
    $atts['maxlength'] = $tag->get_maxlength_option();
    $atts['class'] = $tag->get_class_option($class);
    $atts['id'] = $tag->get_option('id', 'id', true);
    $atts['tabindex'] = $tag->get_option('tabindex', 'int', true);
    $atts['aria-required'] = 'true';
    $pipes = $tag->pipes;
    if (is_a($pipes, 'WPCF7_Pipes') && !$pipes->zero()) {
        $pipe = $pipes->random_pipe();
        $question = $pipe->before;
        $answer = $pipe->after;
    } else {
        // default quiz
        $question = '1+1=?';
        $answer = '2';
    }
    $answer = wpcf7_canonicalize($answer);
    $atts['type'] = 'text';
    $atts['name'] = $tag->name;
    $atts = wpcf7_format_atts($atts);
    $html = sprintf('<span class="wpcf7-form-control-wrap %1$s"><span class="wpcf7-quiz-label">%2$s</span>&nbsp;<input %3$s /><input type="hidden" name="_wpcf7_quiz_answer_%1$s" value="%4$s" />%5$s</span>', $tag->name, esc_html($question), $atts, wp_hash($answer, 'wpcf7_quiz'), $validation_error);
    return $html;
}
Example #25
0
/**
 * Renders the itens id input control (html code)
 * 
 * @param string $tagName defined by the user at form's edit form (inside 
 *                        shortcode brackets)
 * 
 * @return void
 */
function wpcf7_itememail_shortcode_handler($tagName)
{
    global $post;
    $tag = new WPCF7_Shortcode($tagName);
    if (empty($tag->name)) {
        return '';
    }
    $class = wpcf7_form_controls_class($tag->type);
    $class .= ' wpcf7-itememail';
    $post_id = $post->ID;
    $post_meta = get_post_meta($post_id, 'jv_item_email');
    $item_email = reset($post_meta);
    $atts = array();
    $atts['class'] = $tag->get_class_option($class);
    $atts['id'] = $tag->get_id_option();
    $atts['type'] = 'hidden';
    $atts['value'] = $item_email;
    $atts['name'] = $tag->name;
    $atts = wpcf7_format_atts($atts);
    $html = sprintf('<input %1$s />', $atts);
    return $html;
}
function wpcf7_hashcash_validation_filter($result, $tag)
{
    if (!class_exists('WP_Hashcash')) {
        die("WP_Hashcash Class is not available.");
    }
    $instance = WP_Hashcash::get_instance();
    $tag = new WPCF7_Shortcode($tag);
    $hashcashid = $_POST['hashcashid'];
    if (!$hashcashid) {
        die("hashcashid value is not available.");
    }
    $type = $tag->type;
    $name = $tag->name;
    $op = wpcf7_hashcash_options($tag->options);
    $hashcash_result = $instance->verify_hash($hashcashid, $op['complexity']);
    if ($hashcash_result !== 'ok') {
        $result['valid'] = false;
        $result['reason'][$name] = wpcf7_get_message('hashcash_error');
    }
    if (isset($result['reason'][$name]) && ($id = $tag->get_id_option())) {
        $result['idref'][$name] = $id;
    }
    return $result;
}
Example #27
0
function wpcf7_akismet_submitted_params()
{
    $params = array('author' => '', 'author_email' => '', 'author_url' => '', 'content' => '');
    $has_akismet_option = false;
    foreach ((array) $_POST as $key => $val) {
        if ('_wpcf7' == substr($key, 0, 6) || '_wpnonce' == $key) {
            continue;
        }
        if (is_array($val)) {
            $val = implode(', ', wpcf7_array_flatten($val));
        }
        $val = trim($val);
        if (0 == strlen($val)) {
            continue;
        }
        if ($tags = wpcf7_scan_shortcode(array('name' => $key))) {
            $tag = $tags[0];
            $tag = new WPCF7_Shortcode($tag);
            $akismet = $tag->get_option('akismet', '(author|author_email|author_url)', true);
            if ($akismet) {
                $has_akismet_option = true;
                if ('author' == $akismet) {
                    $params[$akismet] = trim($params[$akismet] . ' ' . $val);
                } elseif ('' == $params[$akismet]) {
                    $params[$akismet] = $val;
                }
            }
        }
        $params['content'] .= "\n\n" . $val;
    }
    if (!$has_akismet_option) {
        return false;
    }
    $params['content'] = trim($params['content']);
    return $params;
}
function wpcf7_robottrap_shortcode_handler($tag)
{
    $tag = new WPCF7_Shortcode($tag);
    // default field name
    if (empty($tag->name)) {
        $tag->name = 'email-verify';
    }
    // per field errors
    $validation_error = wpcf7_get_validation_error($tag->name);
    // add wpcf7 specific classes
    $class = wpcf7_form_controls_class('text');
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
    }
    $atts = array();
    $atts['size'] = $tag->get_size_option('40');
    $atts['maxlength'] = $tag->get_maxlength_option();
    $atts['class'] = $tag->get_class_option($class);
    $atts['id'] = $tag->get_id_option();
    $atts['tabindex'] = $tag->get_option('tabindex', 'int', true);
    /**
     * Robots may look for the word "hidden".
     *
     * @ignore Commented out.
     */
    //$atts['aria-hidden'] = 'true';
    $value = (string) reset($tag->values);
    if ($tag->has_option('placeholder') || $tag->has_option('watermark')) {
        $atts['placeholder'] = $value;
        $value = '';
    } elseif ('' === $value) {
        $value = $tag->get_default_option();
    }
    $value = wpcf7_get_hangover($tag->name, $value);
    $atts['value'] = $value;
    $atts['type'] = 'text';
    $atts['name'] = $tag->name;
    $atts = wpcf7_format_atts($atts);
    $html = sprintf('<span class="wpcf7-form-control-wrap %s"><input %s />%s</span>', sanitize_html_class($tag->name), $atts, $validation_error);
    return $html;
}
Example #29
-1
function wpcf7_textarea_validation_filter($result, $tag)
{
    $tag = new WPCF7_Shortcode($tag);
    $type = $tag->type;
    $name = $tag->name;
    $value = isset($_POST[$name]) ? (string) $_POST[$name] : '';
    if ($tag->is_required() && '' == $value) {
        $result->invalidate($tag, wpcf7_get_message('invalid_required'));
    }
    if (!empty($value)) {
        $maxlength = $tag->get_maxlength_option();
        $minlength = $tag->get_minlength_option();
        if ($maxlength && $minlength && $maxlength < $minlength) {
            $maxlength = $minlength = null;
        }
        $code_units = wpcf7_count_code_units($value);
        if (false !== $code_units) {
            if ($maxlength && $maxlength < $code_units) {
                $result->invalidate($tag, wpcf7_get_message('invalid_too_long'));
            } elseif ($minlength && $code_units < $minlength) {
                $result->invalidate($tag, wpcf7_get_message('invalid_too_short'));
            }
        }
    }
    return $result;
}
Example #30
-1
function cf7bs_quiz_shortcode_handler($tag)
{
    $tag = new WPCF7_Shortcode($tag);
    if (empty($tag->name)) {
        return '';
    }
    $status = 'default';
    $validation_error = wpcf7_get_validation_error($tag->name);
    $class = wpcf7_form_controls_class($tag->type);
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
        $status = 'error';
    }
    // size is not used since Bootstrap input fields always scale 100%
    //$atts['size'] = $tag->get_size_option( '40' );
    $pipes = $tag->pipes;
    if (is_a($pipes, 'WPCF7_Pipes') && !$pipes->zero()) {
        $pipe = $pipes->random_pipe();
        $question = $pipe->before;
        $answer = $pipe->after;
    } else {
        // default quiz
        $question = '1+1=?';
        $answer = '2';
    }
    $answer = wpcf7_canonicalize($answer);
    $field = new CF7BS_Form_Field(cf7bs_apply_field_args_filter(array('name' => $tag->name, 'id' => $tag->get_option('id', 'id', true), 'class' => $tag->get_class_option($class), 'type' => 'text', 'value' => '', 'placeholder' => '', 'label' => $tag->content, 'help_text' => $validation_error, 'size' => cf7bs_get_form_property('size'), 'grid_columns' => cf7bs_get_form_property('grid_columns'), 'form_layout' => cf7bs_get_form_property('layout'), 'form_label_width' => cf7bs_get_form_property('label_width'), 'form_breakpoint' => cf7bs_get_form_property('breakpoint'), 'status' => $status, 'maxlength' => $tag->get_maxlength_option(), 'tabindex' => $tag->get_option('tabindex', 'int', true), 'wrapper_class' => $tag->name), $tag->basetype, $tag->name));
    $html = $field->display(false);
    $hidden_html = sprintf('<input type="hidden" name="_wpcf7_quiz_answer_%1$s" value="%2$s">', $tag->name, wp_hash($answer, 'wpcf7_quiz'));
    return str_replace('<input', '<p class="wpcf7-quiz-label">' . esc_html($question) . '</p>' . $hidden_html . '<input', $html);
}