function cf7bs_number_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);
    $class .= ' wpcf7-validates-as-number';
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
        $status = 'error';
    }
    if ($tag->is_required()) {
        $mode = 'required';
    }
    $value = (string) reset($tag->values);
    $placeholder = '';
    if ($tag->has_option('placeholder') || $tag->has_option('watermark')) {
        $placeholder = $value;
        $value = '';
    }
    if (wpcf7_is_posted() && isset($_POST[$tag->name])) {
        $value = stripslashes_deep($_POST[$tag->name]);
    } elseif (isset($_GET) && array_key_exists($tag->name, $_GET)) {
        $value = stripslashes_deep(rawurldecode($_GET[$tag->name]));
    }
    $field = new CF7BS_Form_Field(array('name' => $tag->name, 'id' => $tag->get_option('id', 'id', true), 'class' => $tag->get_class_option($class), 'type' => wpcf7_support_html5() ? $tag->basetype : 'text', 'value' => $value, 'placeholder' => $placeholder, 'label' => $tag->content, 'options' => array('min' => $tag->get_option('min', 'signed_int', true), 'max' => $tag->get_option('max', 'signed_int', true), 'step' => $tag->get_option('step', 'int', true)), '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, 'readonly' => $tag->has_option('readonly') ? true : false, 'tabindex' => $tag->get_option('tabindex', 'int', true), 'wrapper_class' => $tag->name));
    $html = $field->display(false);
    return $html;
}
Beispiel #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;
}
Beispiel #3
0
function wpcf7_file_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['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';
    $atts['type'] = 'file';
    $atts['name'] = $tag->name;
    $atts['value'] = '1';
    $atts = wpcf7_format_atts($atts);
    $html = sprintf('<span class="wpcf7-form-control-wrap %1$s"><input %2$s />%3$s</span>', sanitize_html_class($tag->name), $atts, $validation_error);
    return $html;
}
Beispiel #4
0
 public static function 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, 'wpcf7-date');
     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['type'] = 'text';
     if ($tag->has_option('readonly')) {
         $atts['readonly'] = 'readonly';
     }
     if ($tag->is_required()) {
         $atts['aria-required'] = 'true';
     }
     $value = (string) reset($tag->values);
     if ($tag->has_option('placeholder') || $tag->has_option('watermark')) {
         $atts['placeholder'] = $value;
         $value = '';
     }
     if (wpcf7_is_posted() && isset($_POST[$tag->name])) {
         $value = stripslashes_deep($_POST[$tag->name]);
     }
     $atts['value'] = $value;
     $dpOptions = array();
     $dpOptions['dateFormat'] = str_replace('_', ' ', $tag->get_option('date-format', '', true));
     $dpOptions['minDate'] = $tag->get_option('min-date', '', true);
     $dpOptions['maxDate'] = $tag->get_option('max-date', '', true);
     $dpOptions['firstDay'] = (int) $tag->get_option('first-day', 'int', true);
     $dpOptions['showAnim'] = $tag->get_option('animate', '', true);
     $dpOptions['yearRange'] = str_replace('-', ':', $tag->get_option('year-range', '', true));
     $dpOptions['numberOfMonths'] = (int) $tag->get_option('months', 'int', true);
     $dpOptions['showButtonPanel'] = $tag->has_option('buttons');
     $dpOptions['changeMonth'] = $tag->has_option('change-month');
     $dpOptions['changeYear'] = $tag->has_option('change-year');
     $dpOptions['noWeekends'] = $tag->has_option('no-weekends');
     $inline = $tag->has_option('inline');
     if ($inline) {
         $dpOptions['altField'] = "#{$tag->name}_alt";
         $atts['id'] = "{$tag->name}_alt";
     }
     $atts['type'] = $inline ? 'hidden' : 'text';
     $atts['name'] = $tag->name;
     $atts = wpcf7_format_atts($atts);
     $html = sprintf('<span class="wpcf7-form-control-wrap %1$s"><input %2$s />%3$s %4$s</span>', $tag->name, $atts, $validation_error, $inline ? "<div id=\"{$tag->name}_datepicker\"></div>" : '');
     $html = apply_filters('cf7dp_date_input', $html);
     $dp_selector = $inline ? '#' . $tag->name . '_datepicker' : $tag->name;
     $dp = new CF7_DateTimePicker('date', $dp_selector, $dpOptions);
     self::$inline_js[] = $dp->generate_code($inline);
     return $html;
 }
Beispiel #5
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 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;
}
Beispiel #7
0
function mango_wpcf7_text_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, 'wpcf7-text');
    if (in_array($tag->basetype, array('email', 'url', 'tel'))) {
        $class .= ' wpcf7-validates-as-' . $tag->basetype;
    }
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
    }
    $atts = array();
    $atts_id = '';
    $atts['size'] = $tag->get_size_option('40');
    $atts['maxlength'] = $tag->get_maxlength_option();
    $atts['minlength'] = $tag->get_minlength_option();
    if ($atts['maxlength'] && $atts['minlength'] && $atts['maxlength'] < $atts['minlength']) {
        unset($atts['maxlength'], $atts['minlength']);
    }
    $atts['class'] = $tag->get_class_option($class);
    $atts['id'] = $tag->get_id_option();
    $atts_id = $atts['id'];
    $atts['tabindex'] = $tag->get_option('tabindex', 'int', true);
    if ($tag->has_option('readonly')) {
        $atts['readonly'] = 'readonly';
    }
    if ($tag->is_required()) {
        $atts['aria-required'] = 'true';
    }
    $atts['aria-invalid'] = $validation_error ? 'true' : 'false';
    $value = (string) reset($tag->values);
    if ($tag->has_option('placeholder') || $tag->has_option('watermark')) {
        $atts['placeholder'] = $value;
        $value = '';
    }
    $value = $tag->get_default_option($value);
    $value = wpcf7_get_hangover($tag->name, $value);
    $atts['value'] = $value;
    if (wpcf7_support_html5()) {
        $atts['type'] = $tag->basetype;
    } else {
        $atts['type'] = 'text';
    }
    $atts['name'] = $tag->name;
    $atts = wpcf7_format_atts($atts);
    if ($atts_id == 'disabledInput') {
        $html = sprintf('<input %1$s disabled />%2$s', $atts, $validation_error);
    } else {
        $html = sprintf('<input %1$s />%2$s', $atts, $validation_error);
    }
    return $html;
}
Beispiel #8
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;
}
/**
 * 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;
}
Beispiel #10
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;
}
Beispiel #11
0
function wpcf7_textarea_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['cols'] = $tag->get_cols_option('');
    $atts['rows'] = $tag->get_rows_option('');
    $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);
    if ($tag->has_option('readonly')) {
        $atts['readonly'] = 'readonly';
    }
    if ($tag->is_required()) {
        $atts['aria-required'] = 'true';
    }
    $atts['aria-invalid'] = $validation_error ? 'true' : 'false';
    $value = (string) reset($tag->values);
    if ('' !== $tag->content) {
        $value = $tag->content;
    }
    if ($tag->has_option('placeholder') || $tag->has_option('watermark')) {
        $atts['placeholder'] = $value;
        $value = '';
    }
    if (wpcf7_is_posted() && isset($_POST[$tag->name])) {
        $value = stripslashes_deep($_POST[$tag->name]);
    }
    $atts['name'] = $tag->name;
    $atts = wpcf7_format_atts($atts);
    $html = sprintf('<textarea %2$s></textarea>', $tag->name, $atts, esc_textarea($value), $validation_error);
    return $html;
}
function wpcf7_textarea_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['cols'] = $tag->get_cols_option('40');
    $atts['rows'] = $tag->get_rows_option('10');
    $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);
    if ($tag->has_option('readonly')) {
        $atts['readonly'] = 'readonly';
    }
    if ($tag->is_required()) {
        $atts['aria-required'] = 'true';
    }
    $atts['aria-invalid'] = $validation_error ? 'true' : 'false';
    $value = (string) reset($tag->values);
    if ('' !== $tag->content) {
        $value = $tag->content;
    }
    if ($tag->has_option('placeholder') || $tag->has_option('watermark')) {
        $atts['placeholder'] = $value;
        $value = '';
    }
    $value = wpcf7_get_hangover($tag->name, $value);
    $atts['name'] = $tag->name;
    $atts = wpcf7_format_atts($atts);
    $html = sprintf('<span class="wpcf7-form-control-wrap %1$s"><textarea %2$s>%3$s</textarea>%4$s</span>', sanitize_html_class($tag->name), $atts, esc_textarea($value), $validation_error);
    return $html;
}
function wpcf7_birthday_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, 'wpcf7-birthday');
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
    }
    $atts = array();
    $atts['size'] = $tag->get_size_option('5');
    $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);
    if ($tag->has_option('readonly')) {
        $atts['readonly'] = 'readonly';
    }
    if ($tag->is_required()) {
        $atts['aria-required'] = 'true';
    }
    $atts['aria-invalid'] = $validation_error ? 'true' : 'false';
    $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 %1$s"><input %2$s />%3$s</span>', sanitize_html_class($tag->name), $atts, $validation_error);
    return $html;
}
function wpcf7_confirm_email_validation_filter($result, $tag)
{
    $tag = new WPCF7_Shortcode($tag);
    $type = $tag->basetype;
    $name = $tag->name;
    $values = $tag->values;
    $value = isset($_POST[$name]) ? trim(wp_unslash(strtr((string) $_POST[$name], "\n", " "))) : '';
    if ('confirm_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'));
        } elseif ($value != $_POST['your-email']) {
            $result->invalidate($tag, wpcf7_get_message('invalid_confirm_email'));
        }
    }
    return $result;
}
Beispiel #15
0
function wpcf7_file_validation_filter($result, $tag)
{
    $tag = new WPCF7_Shortcode($tag);
    $name = $tag->name;
    $file = isset($_FILES[$name]) ? $_FILES[$name] : null;
    if ($file['error'] && UPLOAD_ERR_NO_FILE != $file['error']) {
        $result['valid'] = false;
        $result['reason'][$name] = wpcf7_get_message('upload_failed_php_error');
        return $result;
    }
    if (empty($file['tmp_name']) && $tag->is_required()) {
        $result['valid'] = false;
        $result['reason'][$name] = wpcf7_get_message('invalid_required');
        return $result;
    }
    if (!is_uploaded_file($file['tmp_name'])) {
        return $result;
    }
    $allowed_file_types = array();
    if ($file_types_a = $tag->get_option('filetypes')) {
        foreach ($file_types_a as $file_types) {
            $file_types = explode('|', $file_types);
            foreach ($file_types as $file_type) {
                $file_type = trim($file_type, '.');
                $file_type = str_replace(array('.', '+', '*', '?'), array('\\.', '\\+', '\\*', '\\?'), $file_type);
                $allowed_file_types[] = $file_type;
            }
        }
    }
    $allowed_file_types = array_unique($allowed_file_types);
    $file_type_pattern = implode('|', $allowed_file_types);
    $allowed_size = 1048576;
    // default size 1 MB
    if ($file_size_a = $tag->get_option('limit')) {
        $limit_pattern = '/^([1-9][0-9]*)([kKmM]?[bB])?$/';
        foreach ($file_size_a as $file_size) {
            if (preg_match($limit_pattern, $file_size, $matches)) {
                $allowed_size = (int) $matches[1];
                if (!empty($matches[2])) {
                    $kbmb = strtolower($matches[2]);
                    if ('kb' == $kbmb) {
                        $allowed_size *= 1024;
                    } elseif ('mb' == $kbmb) {
                        $allowed_size *= 1024 * 1024;
                    }
                }
                break;
            }
        }
    }
    /* File type validation */
    // Default file-type restriction
    if ('' == $file_type_pattern) {
        $file_type_pattern = 'jpg|jpeg|png|gif|pdf|doc|docx|ppt|pptx|odt|avi|ogg|m4a|mov|mp3|mp4|mpg|wav|wmv';
    }
    $file_type_pattern = trim($file_type_pattern, '|');
    $file_type_pattern = '(' . $file_type_pattern . ')';
    $file_type_pattern = '/\\.' . $file_type_pattern . '$/i';
    if (!preg_match($file_type_pattern, $file['name'])) {
        $result['valid'] = false;
        $result['reason'][$name] = wpcf7_get_message('upload_file_type_invalid');
        return $result;
    }
    /* File size validation */
    if ($file['size'] > $allowed_size) {
        $result['valid'] = false;
        $result['reason'][$name] = wpcf7_get_message('upload_file_too_large');
        return $result;
    }
    $uploads_dir = wpcf7_upload_tmp_dir();
    wpcf7_init_uploads();
    // Confirm upload dir
    $filename = $file['name'];
    // If you get script file, it's a danger. Make it TXT file.
    if (preg_match('/\\.(php|pl|py|rb|cgi)\\d?$/', $filename)) {
        $filename .= '.txt';
    }
    $filename = wp_unique_filename($uploads_dir, $filename);
    $new_file = trailingslashit($uploads_dir) . $filename;
    if (false === @move_uploaded_file($file['tmp_name'], $new_file)) {
        $result['valid'] = false;
        $result['reason'][$name] = wpcf7_get_message('upload_failed');
        return $result;
    }
    // Make sure the uploaded file is only readable for the owner process
    @chmod($new_file, 0400);
    if ($contact_form = wpcf7_get_current_contact_form()) {
        $contact_form->uploaded_files[$name] = $new_file;
        if (empty($contact_form->posted_data[$name])) {
            $contact_form->posted_data[$name] = $filename;
        }
    }
    return $result;
}
Beispiel #16
0
function wpcf7_select_validation_filter($result, $tag)
{
    $tag = new WPCF7_Shortcode($tag);
    $name = $tag->name;
    if (isset($_POST[$name]) && is_array($_POST[$name])) {
        foreach ($_POST[$name] as $key => $value) {
            if ('' === $value) {
                unset($_POST[$name][$key]);
            }
        }
    }
    if ($tag->is_required()) {
        if (!isset($_POST[$name]) || empty($_POST[$name]) && '0' !== $_POST[$name]) {
            $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;
}
function cf7bs_text_shortcode_handler($tag)
{
    $tag_obj = new WPCF7_Shortcode($tag);
    if (empty($tag_obj->name)) {
        return '';
    }
    $mode = $status = 'default';
    $validation_error = wpcf7_get_validation_error($tag_obj->name);
    $class = wpcf7_form_controls_class($tag_obj->type, 'wpcf7-text');
    if (in_array($tag_obj->basetype, array('email', 'url', 'tel'))) {
        $class .= ' wpcf7-validates-as-' . $tag_obj->basetype;
    }
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
        $status = 'error';
    }
    // size is not used since Bootstrap input fields always scale 100%
    //$atts['size'] = $tag_obj->get_size_option( '40' );
    if ($tag_obj->is_required()) {
        $mode = 'required';
    }
    $value = (string) reset($tag_obj->values);
    $placeholder = '';
    if ($tag_obj->has_option('placeholder') || $tag_obj->has_option('watermark')) {
        $placeholder = $value;
        $value = '';
    }
    $value = $tag_obj->get_default_option($value);
    if (wpcf7_is_posted() && isset($_POST[$tag_obj->name])) {
        $value = stripslashes_deep($_POST[$tag_obj->name]);
    } elseif (isset($_GET) && array_key_exists($tag_obj->name, $_GET)) {
        $value = stripslashes_deep(rawurldecode($_GET[$tag_obj->name]));
    }
    $input_before = $tag_obj->get_first_match_option('/input_before:([^\\s]+)/');
    $input_after = $tag_obj->get_first_match_option('/input_after:([^\\s]+)/');
    if (is_array($input_before) && isset($input_before[1])) {
        $input_before = str_replace('---', ' ', $input_before[1]);
    } else {
        $input_before = '';
    }
    if (is_array($input_after) && isset($input_after[1])) {
        $input_after = str_replace('---', ' ', $input_after[1]);
    } else {
        $input_after = '';
    }
    if ($tag_obj->has_option('include_count')) {
        $count_mode = 'input_after';
        $count_down = false;
        $count_options = $tag_obj->get_option('include_count', '[A-Za-z]+(:[A-Za-z]+)?', true);
        if ($count_options) {
            $count_options = explode(':', $count_options);
            foreach ($count_options as $count_option) {
                switch ($count_option) {
                    case 'down':
                    case 'DOWN':
                        $count_down = true;
                        break;
                    case 'before':
                    case 'BEFORE':
                        $count_mode = 'input_before';
                        break;
                    default:
                }
            }
        }
        $tag = cf7bs_text_to_count($tag, $count_down);
        if (!empty(${$count_mode})) {
            ${$count_mode} = wpcf7_count_shortcode_handler($tag) . ' ' . ${$count_mode};
        } else {
            ${$count_mode} = wpcf7_count_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' => wpcf7_support_html5() ? $tag_obj->basetype : 'text', 'value' => $value, 'placeholder' => $placeholder, 'label' => $tag_obj->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, 'readonly' => $tag_obj->has_option('readonly') ? true : false, 'minlength' => $tag_obj->get_minlength_option(), '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), $tag_obj->basetype, $tag_obj->name));
    $html = $field->display(false);
    return $html;
}
Beispiel #18
0
function wpcf7_checkbox_validation_filter($result, $tag)
{
    $tag = new WPCF7_Shortcode($tag);
    $type = $tag->type;
    $name = $tag->name;
    $value = isset($_POST[$name]) ? (array) $_POST[$name] : array();
    if ($tag->is_required() && empty($value)) {
        $result->invalidate($tag, wpcf7_get_message('invalid_required'));
    }
    return $result;
}
Beispiel #19
0
function tm_catdropdown($tag)
{
    $class = '';
    $is_required = 0;
    if (class_exists('WPCF7_Shortcode')) {
        $tag = new WPCF7_Shortcode($tag);
        if ($tag->is_required()) {
            $is_required = 1;
            $class .= ' required-cat';
        }
    }
    $cargs = array('hide_empty' => false, 'exclude' => explode(",", ot_get_option('user_submit_cat_exclude', '')));
    $cats = get_terms('category', $cargs);
    if ($cats) {
        $output = '<div class="wpcf7-form-control-wrap cat"><div class="row wpcf7-form-control wpcf7-checkbox wpcf7-validates-as-required' . $class . '">';
        foreach ($cats as $acat) {
            $output .= '<label class="col-md-4 wpcf7-list-item"><input type="checkbox" name="cat[]" value="' . $acat->term_id . '" /> ' . $acat->name . '</label>';
        }
        $output .= '</div></div>';
    }
    ob_start();
    if ($is_required) {
        ?>
    <script>
	jQuery(document).ready(function(e) {
		jQuery("form.wpcf7-form").submit(function (e) {
			var checked = 0;
			jQuery.each(jQuery("input[name='cat[]']:checked"), function() {
				checked = jQuery(this).val();
			});
			if(checked == 0){
				if(jQuery('.cat-alert').length==0){
					jQuery('.wpcf7-form-control-wrap.cat').append('<span role="alert" class="wpcf7-not-valid-tip cat-alert"><?php 
        _e('Please choose a category', 'cactusthemes');
        ?>
.</span>');
				}
				return false;
			}else{
				return true;
			}
		});
	});
	</script>
	<?php 
    }
    $js_string = ob_get_contents();
    ob_end_clean();
    return $output . $js_string;
}
 public function replace_mail_tags_with_minimum_input($matches)
 {
     // allow [[foo]] syntax for escaping a tag
     if ($matches[1] == '[' && $matches[4] == ']') {
         return substr($matches[0], 1, -1);
     }
     $tag = $matches[0];
     $tagname = $matches[2];
     $values = $matches[3];
     if (!empty($values)) {
         preg_match_all('/"[^"]*"|\'[^\']*\'/', $values, $matches);
         $values = wpcf7_strip_quote_deep($matches[0]);
     }
     $do_not_heat = false;
     if (preg_match('/^_raw_(.+)$/', $tagname, $matches)) {
         $tagname = trim($matches[1]);
         $do_not_heat = true;
     }
     $format = '';
     if (preg_match('/^_format_(.+)$/', $tagname, $matches)) {
         $tagname = trim($matches[1]);
         $format = $values[0];
     }
     $example_email = '*****@*****.**';
     $example_text = 'example';
     $example_blank = '';
     $form_tags = $this->contact_form->form_scan_shortcode(array('name' => $tagname));
     if ($form_tags) {
         $form_tag = new WPCF7_Shortcode($form_tags[0]);
         $is_required = $form_tag->is_required() || 'radio' == $form_tag->type;
         if (!$is_required) {
             return $example_blank;
         }
         $is_selectable = in_array($form_tag->basetype, array('radio', 'checkbox', 'select'));
         if ($is_selectable) {
             if ($form_tag->pipes instanceof WPCF7_Pipes) {
                 if ($do_not_heat) {
                     $before_pipes = $form_tag->pipes->collect_befores();
                     $last_item = array_pop($before_pipes);
                 } else {
                     $after_pipes = $form_tag->pipes->collect_afters();
                     $last_item = array_pop($after_pipes);
                 }
             } else {
                 $last_item = array_pop($form_tag->values);
             }
             if ($last_item && wpcf7_is_mailbox_list($last_item)) {
                 return $example_email;
             } else {
                 return $example_text;
             }
         }
         if ('email' == $form_tag->basetype) {
             return $example_email;
         } else {
             return $example_text;
         }
     } else {
         $tagname = preg_replace('/^wpcf7\\./', '_', $tagname);
         // for back-compat
         if ('_post_author_email' == $tagname) {
             return $example_email;
         } elseif ('_' == substr($tagname, 0, 1)) {
             // maybe special mail tag
             return $example_text;
         }
     }
     return $tag;
 }
function wpcf7_mailpoetsignup_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['class'] = $tag->get_class_option( $class );
	$atts['id'] = $tag->get_option( 'id', 'id', true );

	// get checkbox value
	// first get all of the lists
	$lists = wpcf7_mailpoetsignup_get_lists();
	if ( ! empty ( $lists ) ) {
		$checkbox_values = array();
		foreach ( $lists as $key => $l ) {
			// check if that list was added to the form
			if ( $tag->has_option( 'mailpoet_list_' . $l['list_id'] ) ) {
				// add the list id into the array of checkbox values
				$checkbox_values[] = $l['list_id'];
			}
		}
	}

	// we still want a value for the checkbox so *some* data gets posted
	if ( ! empty ( $checkbox_values ) ) {
		// now implode them all into a comma separated string
		$atts['value'] = implode( $checkbox_values, "," );
	} else {
		// set a 0 so we know to add the user to Mailpoet but not to any specific list
		$atts['value'] = "0";
	}


	if ( $tag->is_required() ) {
		$atts['aria-required'] = 'true';
	}

	// set default checked state
	$atts['checked'] = "";
	if ( $tag->has_option( 'default:on' ) ) {
		$atts['checked'] = 'checked';
	}

	$value = (string) reset( $tag->values );

	if ( '' !== $tag->content ) {
		$value = $tag->content;
	}

	if ( wpcf7_is_posted() && isset( $_POST[$tag->name] ) ) {
		$value = stripslashes_deep( $_POST[$tag->name] );
	}

	$atts['name'] = $tag->name;
	$id = $atts['id'] = $atts['name'];

	$atts = wpcf7_format_atts( $atts );

	// get the content from the tag to make the checkbox label
	$label = __( 'Sign up for the newsletter', 'mpcf7' );
	$values = $tag->values;
	if( isset( $values ) && !empty ($values) ){
		$label = esc_textarea( $values[0] );
	}

	$html = sprintf(
		'<span class="wpcf7-form-control-wrap %1$s"><input type="checkbox" %2$s />&nbsp;</span><label for="%3$s">%4$s</label>&nbsp;%5$s',
		$tag->name, $atts, $id, $value, $validation_error );

	return $html;
}
Beispiel #22
0
function wpcf7_mailpoetsignup_shortcode_handler($tag)
{
    // if cf7 is not active, leave
    if (!class_exists('WPCF7_Shortcode')) {
        return;
    }
    // create a new tag
    $tag = new WPCF7_Shortcode($tag);
    // if the tag doesn't have a name, return empty handed
    if (empty($tag->name)) {
        return '';
    }
    // check for errors and set the class
    $validation_error = wpcf7_get_validation_error($tag->name);
    $class = wpcf7_form_controls_class($tag->type);
    // if there were errors, add class
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
    }
    // init the atts array, add the class and id set in the shortcode
    $atts = array();
    $atts['class'] = $tag->get_class_option($class);
    $atts['id'] = $tag->get_option('id', 'id', true);
    // get checkbox value
    // first get all of the lists
    $lists = wpcf7_mailpoetsignup_get_lists();
    if (!empty($lists)) {
        $checkbox_values = array();
        // go through each list
        foreach ($lists as $key => $l) {
            // check if that list was added to the form
            if ($tag->has_option('mailpoet_list_' . $l['list_id'])) {
                // add the list into the array of checkbox values
                $checkbox_values[] = 'mailpoet_list_' . $l['list_id'];
            }
        }
    }
    // do we have any lists?
    if (!empty($checkbox_values)) {
        // implode them all into a comma separated string
        $atts['value'] = implode($checkbox_values, ',');
    } else {
        // we apparently have no lists
        // set a 0 so we know to add the user to Mailpoet but not to any specific list
        $atts['value'] = '0';
    }
    // is it required?
    if ($tag->is_required()) {
        $atts['aria-required'] = 'true';
    }
    // set default checked state
    $atts['checked'] = $tag->has_option('default:on') ? 'checked' : '';
    // default tag value
    $value = (string) reset($tag->values);
    // if the tag has a default value, add it
    if ('' !== $tag->content) {
        $value = $tag->content;
    }
    // if the tag has a posted value, add it
    if (wpcf7_is_posted() && isset($_POST[$tag->name])) {
        $value = stripslashes_deep($_POST[$tag->name]);
    }
    // set the name and the id of the field
    $atts['name'] = $tag->name;
    $id = !empty($atts['id']) ? $atts['id'] : $atts['name'];
    // put all of the atts into a string for the field
    $atts = wpcf7_format_atts($atts);
    // get the content from the tag to make the checkbox label
    $label = __('Sign up for the newsletter', 'mpcf7');
    $values = $tag->values;
    if (isset($values) && !empty($values)) {
        $label = esc_textarea($values[0]);
    }
    // should the label be inside the span?
    if ($tag->has_option('label-inside-span')) {
        // create the field
        $html = sprintf('<span class="wpcf7-form-control-wrap %1$s"><input type="checkbox" %2$s />&nbsp;<label for="%3$s">%4$s</label></span>&nbsp;%5$s', $tag->name, $atts, $id, $value, $validation_error);
    } else {
        // create the field
        $html = sprintf('<span class="wpcf7-form-control-wrap %1$s"><input type="checkbox" %2$s />&nbsp;</span><label for="%3$s">%4$s</label>&nbsp;%5$s', $tag->name, $atts, $id, $value, $validation_error);
    }
    return $html;
}
function cf7bs_checkbox_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';
    }
    $exclusive = $tag->has_option('exclusive');
    $free_text = $tag->has_option('free_text');
    $multiple = false;
    if ('checkbox' == $tag->basetype) {
        $multiple = !$exclusive;
    } else {
        $exclusive = false;
    }
    if ($exclusive) {
        $class .= ' wpcf7-exclusive-checkbox';
    }
    if ($tag->is_required()) {
        $mode = 'required';
    }
    $values = (array) $tag->values;
    $labels = (array) $tag->labels;
    if ($data = (array) $tag->get_data_option()) {
        if ($free_text) {
            $values = array_merge(array_slice($values, 0, -1), array_values($data), array_slice($values, -1));
            $labels = array_merge(array_slice($labels, 0, -1), array_values($data), array_slice($labels, -1));
        } else {
            $values = array_merge($values, array_values($data));
            $labels = array_merge($labels, array_values($data));
        }
    }
    $defaults = array();
    $default_choice = $tag->get_default_option(null, 'multiple=1');
    foreach ($default_choice as $value) {
        $key = array_search($value, $values, true);
        if (false !== $key) {
            $defaults[] = (int) $key + 1;
        }
    }
    if ($matches = $tag->get_first_match_option('/^default:([0-9_]+)$/')) {
        $defaults = array_merge($defaults, explode('_', $matches[1]));
    }
    $defaults = array_unique($defaults);
    $options = array();
    $checked = '';
    if ($multiple) {
        $checked = array();
    }
    if (isset($_POST[$tag->name])) {
        $post = $_POST[$tag->name];
    } else {
        if (isset($_GET[$tag->name])) {
            if ($multiple) {
                $get = cf7bs_array_decode(rawurldecode($_GET[$tag->name]));
            } else {
                $get = rawurldecode($_GET[$tag->name]);
            }
        }
        $post = $multiple ? array() : '';
    }
    $posted = wpcf7_is_posted();
    $count = 0;
    foreach ((array) $tag->values as $key => $value) {
        if ($free_text && $count == count($tag->values) - 1) {
            $options[$value] = '<input type="text" name="' . sprintf('_wpcf7_%1$s_free_text_%2$s', $tag->basetype, $tag->name) . '" class="wpcf7-free-text">';
        } else {
            $options[$value] = isset($labels[$key]) ? $labels[$key] : $value;
        }
        if ($posted && !empty($post)) {
            if ($multiple && in_array(esc_sql($value), (array) $post)) {
                $checked[] = $value;
            }
            if (!$multiple && $post == esc_sql($value)) {
                $checked = $value;
            }
        } elseif (isset($get) && !empty($get)) {
            if ($multiple && in_array(esc_sql($value), (array) $get)) {
                $checked[] = $value;
            }
            if (!$multiple && $get == esc_sql($value)) {
                $checked = $value;
            }
        } elseif (in_array($key + 1, (array) $defaults)) {
            if ($multiple) {
                $checked[] = $value;
            } else {
                $checked = $value;
            }
        }
        $count++;
    }
    $label = $tag->content;
    if (count($options) < 1) {
        if ($free_text) {
            $options = array('true' => '<input type="text" name="' . sprintf('_wpcf7_%1$s_free_text_%2$s', $tag->basetype, $tag->name) . '" class="wpcf7-free-text">');
        } else {
            $options = array('true' => $label);
            $label = '';
        }
    }
    $field = new CF7BS_Form_Field(cf7bs_apply_field_args_filter(array('name' => $tag->name, 'id' => $tag->get_option('id', 'id', true), 'class' => '', 'type' => $tag->basetype, 'value' => $checked, 'label' => $label, 'options' => $options, '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'), 'group_layout' => cf7bs_get_form_property('group_layout'), 'group_type' => cf7bs_get_form_property('group_type'), 'mode' => $mode, 'status' => $status, 'tabindex' => $tag->get_option('tabindex', 'int', true), 'wrapper_class' => $tag->get_class_option($class . ' ' . $tag->name)), $tag->basetype, $tag->name));
    $html = $field->display(false);
    return $html;
}
Beispiel #24
0
function cf7bs_select_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';
    }
    if ($tag->is_required()) {
        $mode = 'required';
    }
    $defaults = array();
    $default_choice = $tag->get_default_option(null, 'multiple=1');
    foreach ($default_choice as $value) {
        $key = array_search($value, $values, true);
        if (false !== $key) {
            $defaults[] = (int) $key + 1;
        }
    }
    if ($matches = $tag->get_first_match_option('/^default:([0-9_]+)$/')) {
        $defaults = explode('_', $matches[1]);
    }
    $defaults = array_unique($defaults);
    $multiple = $tag->has_option('multiple');
    $include_blank = $tag->has_option('include_blank');
    $first_as_label = $tag->has_option('first_as_label');
    $values = $tag->values;
    $labels = $tag->labels;
    if ($data = (array) $tag->get_data_option()) {
        $values = array_merge($values, array_values($data));
        $labels = array_merge($labels, array_values($data));
    }
    $empty_select = empty($values);
    $shifted = false;
    if ($empty_select || $include_blank) {
        array_unshift($labels, '---');
        array_unshift($values, '');
        $shifted = true;
    } elseif ($first_as_label) {
        $values[0] = '';
    }
    $options = array();
    $selected = '';
    if ($multiple) {
        $selected = array();
    }
    if (isset($_POST[$tag->name])) {
        $post = $_POST[$tag->name];
    } else {
        if (isset($_GET[$tag->name])) {
            if ($multiple) {
                $get = cf7bs_array_decode(rawurldecode($_GET[$tag->name]));
            } else {
                $get = rawurldecode($_GET[$tag->name]);
            }
        }
        $post = $multiple ? array() : '';
    }
    $posted = wpcf7_is_posted();
    foreach ($values as $key => $value) {
        $options[$value] = isset($labels[$key]) ? $labels[$key] : $value;
        if ($posted && !empty($post)) {
            if ($multiple && in_array(esc_sql($value), (array) $post)) {
                $selected[] = $value;
            }
            if (!$multiple && $post == esc_sql($value)) {
                $selected = $value;
            }
        } elseif (isset($get) && !empty($get)) {
            if ($multiple && in_array(esc_sql($value), (array) $get)) {
                $selected[] = $value;
            }
            if (!$multiple && $get == esc_sql($value)) {
                $selected = $value;
            }
        } elseif (!$shifted && in_array((int) $key + 1, (array) $defaults) || $shifted && in_array((int) $key, (array) $defaults)) {
            if ($multiple) {
                $selected[] = $value;
            } else {
                $selected = $value;
            }
        }
    }
    $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' => $multiple ? 'multiselect' : 'select', 'value' => $selected, 'label' => $tag->content, 'options' => $options, '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;
}
Beispiel #25
0
function wpcf7_select_validation_filter($result, $tag)
{
    $tag = new WPCF7_Shortcode($tag);
    $name = $tag->name;
    if (isset($_POST[$name]) && is_array($_POST[$name])) {
        foreach ($_POST[$name] as $key => $value) {
            if ('' === $value) {
                unset($_POST[$name][$key]);
            }
        }
    }
    $empty = !isset($_POST[$name]) || empty($_POST[$name]) && '0' !== $_POST[$name];
    if ($tag->is_required() && $empty) {
        $result->invalidate($tag, wpcf7_get_message('invalid_required'));
    }
    return $result;
}
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;
}
 /**
  * Outputs the HTML for the textarea shortcode.  We're replacing the default
  * CF7 textarea shortcode.  If the user wants a word limit instead of a character
  * limit, we need to remove the maxlength attribute from the element.
  *
  * @param $tag
  * @return string
  */
 function textarea_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['cols'] = $tag->get_cols_option('40');
     $atts['rows'] = $tag->get_rows_option('10');
     $atts['maxlength'] = $tag->get_maxlength_option();
     $atts['minlength'] = $tag->get_minlength_option();
     if ($atts['maxlength'] && $atts['minlength'] && $atts['maxlength'] < $atts['minlength']) {
         unset($atts['maxlength'], $atts['minlength']);
     }
     $maxlengthwords = false;
     $minlengthwords = false;
     // Check whether the field has a min or max word length
     foreach ($tag->options as $key => $option) {
         if (stristr($option, 'maxlengthwords:true')) {
             $maxlengthwords = true;
         }
         if (stristr($option, 'minlengthwords:true')) {
             $minlengthwords = true;
         }
     }
     // If this field has either the min or max word length validation,
     // remove the maxlength and minlength variables because we aren't
     // validating for character length
     if ($maxlengthwords === true || $minlengthwords === true) {
         unset($atts['maxlength'], $atts['minlength']);
     }
     $atts['class'] = $tag->get_class_option($class);
     $atts['id'] = $tag->get_id_option();
     $atts['tabindex'] = $tag->get_option('tabindex', 'int', true);
     if ($tag->has_option('readonly')) {
         $atts['readonly'] = 'readonly';
     }
     if ($tag->is_required()) {
         $atts['aria-required'] = 'true';
     }
     $atts['aria-invalid'] = $validation_error ? 'true' : 'false';
     $value = empty($tag->content) ? (string) reset($tag->values) : $tag->content;
     if ($tag->has_option('placeholder') || $tag->has_option('watermark')) {
         $atts['placeholder'] = $value;
         $value = '';
     }
     $value = $tag->get_default_option($value);
     $value = wpcf7_get_hangover($tag->name, $value);
     $atts['name'] = $tag->name;
     $atts = wpcf7_format_atts($atts);
     $html = sprintf('<span class="wpcf7-form-control-wrap %1$s"><textarea %2$s>%3$s</textarea>%4$s</span>', sanitize_html_class($tag->name), $atts, esc_textarea($value), $validation_error);
     return $html;
 }
 public function tb_filter_validation($result, $tag)
 {
     $tag = new WPCF7_Shortcode($tag);
     $name = $tag->name;
     $value = isset($_POST[$name]) ? trim(wp_unslash(strtr((string) $_POST[$name], "\n", " "))) : '';
     if ($tag->is_required() && '' == $value) {
         $result->invalidate($tag, wpcf7_get_message('invalid_required'));
     }
     return $result;
 }
Beispiel #29
0
     $class .= ' wpcf7-not-valid';
 }
 $atts = [];
 $atts['size'] = $tag->get_size_option('40');
 $atts['maxlength'] = $tag->get_maxlength_option();
 $atts['minlength'] = $tag->get_minlength_option();
 if ($atts['maxlength'] && $atts['minlength'] && $atts['maxlength'] < $atts['minlength']) {
     unset($atts['maxlength'], $atts['minlength']);
 }
 $atts['class'] = $tag->get_class_option($class);
 $atts['id'] = $tag->get_id_option();
 $atts['tabindex'] = $tag->get_option('tabindex', 'int', true);
 if ($tag->has_option('readonly')) {
     $atts['readonly'] = 'readonly';
 }
 if ($tag->is_required()) {
     $atts['aria-required'] = 'true';
     $atts['required'] = 'true';
 }
 $atts['aria-invalid'] = $validation_error ? 'true' : 'false';
 $value = (string) reset($tag->values);
 if ($tag->has_option('placeholder') || $tag->has_option('watermark')) {
     $atts['placeholder'] = $value;
     $value = '';
 }
 $value = $tag->get_default_option($value);
 $value = wpcf7_get_hangover($tag->name, $value);
 $atts['value'] = $value;
 if (wpcf7_support_html5()) {
     $atts['type'] = $tag->basetype;
 } else {
Beispiel #30
-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;
}