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; }
function cf7bs_recaptcha_shortcode_handler($tag) { $tag_obj = new WPCF7_Shortcode($tag); $field = new CF7BS_Form_Field(cf7bs_apply_field_args_filter(array('name' => wpcf7_recaptcha_shortcode_handler($tag), 'type' => 'custom', 'label' => $tag_obj->content, '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)); $html = $field->display(false); return $html; }
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_count_shortcode_handler($tag) { $tag_obj = new WPCF7_Shortcode($tag); if (empty($tag_obj->name)) { return ''; } $field = new CF7BS_Form_Field(array('name' => wpcf7_count_shortcode_handler($tag), 'type' => 'custom', 'label' => $tag_obj->content, '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' => '')); $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 cf7bs_acceptance_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->has_option('invert')) { $class .= ' wpcf7-invert'; } $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' => 'checkbox', 'value' => $tag->has_option('default:on') ? '1' : '0', 'options' => array('1' => $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'), 'group_layout' => cf7bs_get_form_property('group_layout'), '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_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; }
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; }
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; }
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); }