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_captchar_to_captchac($tag) { $tag['type'] = 'captchac'; $tag['basetype'] = 'captchac'; $tag['options'] = array(); $size = cf7bs_get_form_property('size'); $image_size = 'large' == $size ? 'l' : ('small' == $size ? 's' : 'm'); $tag['options'][] = 'size:' . $image_size; return $tag; }
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 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; }
public function display($echo = true) { $output = apply_filters('cf7bs_bootstrap_form_field_display', '', $this->args); if (empty($output)) { $output = ''; extract($this->args); $type = $this->validate_type($type); $value = $this->validate_value($value, $type, $options); if ('hidden' != $type) { $label_class = 'control-label'; $input_div_class = ''; $input_class = $class; if ('horizontal' == $form_layout) { $classes = $this->get_column_width_classes($form_label_width, $form_breakpoint, $grid_columns); $label_class .= ' ' . $classes['label']; $input_div_class = $classes['input']; if (empty($label)) { $input_div_class .= ' ' . $this->get_column_offset_class($form_label_width, $form_breakpoint, $grid_columns); } } elseif ('inline' == $form_layout) { if (empty($placeholder)) { $placeholder = $label; } } if (!empty($wrapper_class)) { $wrapper_class = ' ' . esc_attr($wrapper_class); } if (!in_array($type, array('radio', 'checkbox'))) { if (!empty($input_class)) { $input_class .= ' '; } if (!in_array($type, array('file', 'range'))) { $input_class .= 'form-control'; } if ('textarea' != $type) { if ('large' == $size) { $input_class .= ' input-lg'; } elseif (in_array($size, array('small', 'mini'))) { $input_class .= ' input-sm'; } } if (is_int($tabindex)) { $tabindex = ' tabindex="' . $tabindex . '"'; } else { $tabindex = ''; } } if (!empty($input_class)) { $input_class = ' class="' . esc_attr($input_class) . '"'; } if (!empty($placeholder)) { $placeholder = ' placeholder="' . esc_attr($placeholder) . '"'; } if ($readonly) { $readonly = ' readonly'; } else { $readonly = ''; } if ($minlength && $minlength > 0) { $minlength = ' minlength="' . absint($minlength) . '"'; } else { $minlength = ''; } if ($maxlength && $maxlength > -1) { $maxlength = ' maxlength="' . absint($maxlength) . '"'; } else { $maxlength = ''; } $append = ''; if (in_array($status, array('success', 'warning', 'error'))) { $status = ' has-' . $status; } else { $status = ''; } if ('has-error' == $status) { $append .= ' aria-invalid="true"'; } else { $append .= ' aria-invalid="false"'; } $label_required = ''; if ('required' == $mode) { $append .= ' aria-required="true" required'; $label_required = ' ' . cf7bs_get_form_property('required_html'); } elseif ('disabled' == $mode) { $append .= ' disabled'; } if ('horizontal' == $form_layout) { $output .= '<div class="form-group' . $wrapper_class . $status . '">'; if (!empty($label)) { $output .= '<label class="' . esc_attr($label_class) . '"' . (!empty($id) ? ' for="' . esc_attr($id) . '"' : '') . '>' . esc_html($label) . $label_required . '</label>'; } $output .= '<div class="' . esc_attr($input_div_class) . '">'; } elseif ('inline' == $form_layout) { $output .= '<div class="form-group' . $wrapper_class . $status . '">'; if (!empty($label)) { $output .= '<label class="sr-only"' . (!empty($id) ? ' for="' . esc_attr($id) . '"' : '') . '>' . esc_html($label) . $label_required . '</label>'; } } else { $output .= '<div class="form-group' . $wrapper_class . $status . '">'; if (!empty($label)) { $rc_group_style = ''; if (in_array($type, array('radio', 'checkbox'))) { $rc_group_style = ' style="display:block;"'; } $output .= '<label' . (!empty($id) ? ' for="' . esc_attr($id) . '"' : '') . $rc_group_style . '>' . esc_html($label) . $label_required . '</label>'; } } } switch ($type) { case 'checkbox': if (count($options) <= 1) { $curval = key($options); $title = $options[$curval]; if (false === strpos($title, 'wpcf7-free-text')) { $title = esc_html($title); } $output .= '<div class="checkbox' . $wrapper_class . '">'; $output .= '<label>'; $output .= '<input' . $input_class . (!empty($id) ? ' id="' . esc_attr($id) . '"' : '') . ' name="' . esc_attr($name) . '" type="checkbox" value="' . esc_attr($curval) . '"' . cf7bs_checked($value, $curval, false) . (is_int($tabindex) ? ' tabindex="' . $tabindex . '"' : '') . $append . '>'; $output .= $title; $output .= '</label>'; $output .= '</div>'; } else { if ('buttons' == $group_layout) { $button_group = new CF7BS_Button_Group(array('mode' => 'checkbox', 'size' => $size)); $output .= $button_group->open(false); $counter = 0; foreach ($options as $curval => $title) { $is_checked = cf7bs_multiple_checked($value, $curval, false); $output .= $button_group->insert_button(array('type' => $group_type, 'id' => $id . ($counter + 1), 'name' => $name . '[]', 'class' => $class, 'value' => $curval, 'title' => $title, 'append' => (is_int($tabindex) ? ' tabindex="' . ($tabindex + $counter) . '"' : '') . $is_checked . $append), false); $counter++; } $output .= $button_group->close(false); } elseif ('inline' == $group_layout && 'inline' != $form_layout) { $counter = 0; foreach ($options as $curval => $title) { if (false === strpos($title, 'wpcf7-free-text')) { $title = esc_html($title); } $output .= '<label class="checkbox-inline">'; $output .= '<input' . $input_class . (!empty($id) ? ' id="' . esc_attr($id . ($counter + 1)) . '"' : '') . ' name="' . esc_attr($name . '[]') . '" type="checkbox" value="' . esc_attr($curval) . '"' . cf7bs_multiple_checked($value, $curval, false) . ($tabindex >= 0 ? ' tabindex="' . ($tabindex + $counter) . '"' : '') . $append . '>'; $output .= $title; $output .= '</label>'; $counter++; } } else { $counter = 0; foreach ($options as $curval => $title) { if (false === strpos($title, 'wpcf7-free-text')) { $title = esc_html($title); } $output .= '<div class="checkbox">'; $output .= '<label>'; $output .= '<input' . $input_class . (!empty($id) ? ' id="' . esc_attr($id . ($counter + 1)) . '"' : '') . ' name="' . esc_attr($name . '[]') . '" type="checkbox" value="' . esc_attr($curval) . '"' . cf7bs_multiple_checked($value, $curval, false) . (is_int($tabindex) ? ' tabindex="' . ($tabindex + $counter) . '"' : '') . $append . '>'; $output .= $title; $output .= '</label>'; $output .= '</div>'; $counter++; } } } break; case 'select': $output .= '<select' . $input_class . (!empty($id) ? ' id="' . esc_attr($id) . '"' : '') . ' name="' . esc_attr($name) . '"' . $tabindex . $append . '>'; foreach ($options as $curval => $title) { $output .= '<option value="' . esc_attr($curval) . '"' . cf7bs_selected($value, $curval, false) . '>' . esc_html($title) . '</option>'; } $output .= '</select>'; break; case 'multiselect': $output .= '<select' . $input_class . (!empty($id) ? ' id="' . esc_attr($id) . '"' : '') . ' name="' . esc_attr($name . '[]') . '" multiple' . $tabindex . $append . '>'; foreach ($options as $curval => $title) { $output .= '<option value="' . esc_attr($curval) . '"' . cf7bs_multiple_selected($value, $curval, false) . '>' . esc_html($title) . '</option>'; } $output .= '</select>'; break; case 'radio': if (count($options) <= 1) { $curval = key($options); $title = $options[$curval]; if (false === strpos($title, 'wpcf7-free-text')) { $title = esc_html($title); } $output .= '<div class="radio' . $wrapper_class . '">'; $output .= '<label>'; $output .= '<input' . $input_class . (!empty($id) ? ' id="' . esc_attr($id) . '"' : '') . ' name="' . esc_attr($name) . '" type="radio" value="' . esc_attr($curval) . '"' . cf7bs_checked($value, $curval, false) . (is_int($tabindex) ? ' tabindex="' . $tabindex . '"' : '') . $append . '>'; $output .= $title; $output .= '</label>'; $output .= '</div>'; } else { if ('buttons' == $group_layout) { $button_group = new CF7BS_Button_Group(array('mode' => 'radio', 'size' => $size)); $output .= $button_group->open(false); $counter = 0; foreach ($options as $curval => $title) { $is_checked = cf7bs_checked($value, $curval, false); $output .= $button_group->insert_button(array('type' => $group_type, 'id' => $id . ($counter + 1), 'name' => $name, 'class' => $class, 'value' => $curval, 'title' => $title, 'append' => (is_int($tabindex) ? ' tabindex="' . ($tabindex + $counter) . '"' : '') . $is_checked . $append), false); $counter++; } $output .= $button_group->close(false); } elseif ('inline' == $group_layout && 'inline' != $form_layout) { $counter = 0; foreach ($options as $curval => $title) { if (false === strpos($title, 'wpcf7-free-text')) { $title = esc_html($title); } $output .= '<label class="radio-inline">'; $output .= '<input' . $input_class . (!empty($id) ? ' id="' . esc_attr($id . ($counter + 1)) . '"' : '') . ' name="' . esc_attr($name) . '" type="radio" value="' . esc_attr($curval) . '"' . cf7bs_checked($value, $curval, false) . ($tabindex >= 0 ? ' tabindex="' . ($tabindex + $counter) . '"' : '') . $append . '>'; $output .= $title; $output .= '</label>'; $counter++; } } else { $counter = 0; foreach ($options as $curval => $title) { if (false === strpos($title, 'wpcf7-free-text')) { $title = esc_html($title); } $output .= '<div class="radio">'; $output .= '<label>'; $output .= '<input' . $input_class . (!empty($id) ? ' id="' . esc_attr($id . ($counter + 1)) . '"' : '') . ' name="' . esc_attr($name) . '" type="radio" value="' . esc_attr($curval) . '"' . cf7bs_checked($value, $curval, false) . (is_int($tabindex) ? ' tabindex="' . ($tabindex + $counter) . '"' : '') . $append . '>'; $output .= $title; $output .= '</label>'; $output .= '</div>'; $counter++; } } } break; case 'textarea': if (!empty($input_before) && 'inline' != $form_layout) { $input_before_class = trim(str_replace('input-group-addon', '', $input_before_class)); $output .= '<p class="text-right' . (!empty($input_before_class) ? ' ' . $input_before_class : '') . '">' . $input_before . '</p>'; } $output .= '<textarea' . $input_class . (!empty($id) ? ' id="' . esc_attr($id) . '"' : '') . ' name="' . esc_attr($name) . '" rows="' . absint($rows) . '"' . $placeholder . $readonly . $minlength . $maxlength . $tabindex . $append . '>'; $output .= esc_textarea($value); $output .= '</textarea>'; if (!empty($input_after) && 'inline' != $form_layout) { $input_after_class = trim(str_replace('input-group-addon', '', $input_after_class)); $output .= '<p class="text-right' . (!empty($input_after_class) ? ' ' . $input_after_class : '') . '">' . $input_after . '</p>'; } break; case 'file': $output .= '<input' . $input_class . (!empty($id) ? ' id="' . esc_attr($id) . '"' : '') . ' name="' . esc_attr($name) . '" type="file"' . $tabindex . $append . '>'; break; case 'hidden': $output .= '<input' . (!empty($id) ? ' id="' . esc_attr($id) . '"' : '') . ' name="' . esc_attr($name) . '" type="hidden" value="' . esc_attr($value) . '">'; break; case 'number': case 'range': case 'date': case 'datetime': case 'datetime-local': case 'month': case 'time': case 'week': $min = ''; if (isset($options['min'])) { $min = ' min="' . esc_attr($options['min']) . '"'; } $max = ''; if (isset($options['max'])) { $max = ' max="' . esc_attr($options['max']) . '"'; } $step = ''; if (isset($options['step'])) { $step = ' step="' . esc_attr($options['step']) . '"'; } $output .= '<input' . $input_class . (!empty($id) ? ' id="' . esc_attr($id) . '"' : '') . ' name="' . esc_attr($name) . '" type="' . esc_attr($type) . '" value="' . esc_attr($value) . '"' . $placeholder . $min . $max . $step . $readonly . $tabindex . $append . '>'; break; case 'custom': if (!empty($name)) { $output .= $name; } break; default: if ('static' == $mode) { $output .= '<p class="form-control-static">' . esc_html($value) . '</p>'; } else { if (!empty($input_before) || !empty($input_after)) { $input_group_class = 'input-group'; if (false !== strpos($input_class, ' input-lg')) { $input_class = str_replace(' input-lg', '', $input_class); $input_group_class .= ' input-group-lg'; } elseif (false !== strpos($input_class, ' input-sm')) { $input_class = str_replace(' input-sm', '', $input_class); $input_group_class .= ' input-group-sm'; } $output .= '<div class="' . $input_group_class . '">'; if (!empty($input_before)) { $output .= '<span class="' . esc_attr($input_before_class) . '">'; $output .= $input_before; $output .= '</span>'; } } $output .= '<input' . $input_class . (!empty($id) ? ' id="' . esc_attr($id) . '"' : '') . ' name="' . esc_attr($name) . '" type="' . esc_attr($type) . '" value="' . esc_attr($value) . '"' . $placeholder . $readonly . $minlength . $maxlength . $tabindex . $append . '>'; if (!empty($input_before) || !empty($input_after)) { if (!empty($input_after)) { $output .= '<span class="' . esc_attr($input_after_class) . '">'; $output .= $input_after; $output .= '</span>'; } $output .= '</div>'; } } break; } if ('hidden' != $type) { if (!empty($help_text) && 'inline' != $form_layout) { $output .= '<span class="help-block">' . $help_text . '</span>'; } if ('horizontal' == $form_layout) { $output .= '</div>'; $output .= '</div>'; } else { $output .= '</div>'; } } } if ($echo) { echo $output; } return $output; }
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_form_class_attr($class = '') { $layout = cf7bs_get_form_property('layout'); if (in_array($layout, array('horizontal', 'inline'))) { if (!empty($class)) { $class .= ' '; } $class .= 'form-' . $layout; } return $class; }
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); }