function wpcf7_count_shortcode_handler($tag) { $tag = new WPCF7_Shortcode($tag); if (empty($tag->name)) { return ''; } $target = wpcf7_scan_shortcode(array('name' => $tag->name)); $maxlength = $minlength = null; if ($target) { $target = new WPCF7_Shortcode($target[0]); $maxlength = $target->get_maxlength_option(); $minlength = $target->get_minlength_option(); if ($maxlength && $minlength && $maxlength < $minlength) { $maxlength = $minlength = null; } } if ($tag->has_option('down')) { $value = (int) $maxlength; $class = 'wpcf7-character-count down'; } else { $value = '0'; $class = 'wpcf7-character-count up'; } $atts = array(); $atts['id'] = $tag->get_id_option(); $atts['class'] = $tag->get_class_option($class); $atts['data-target-name'] = $tag->name; $atts['data-starting-value'] = $value; $atts['data-current-value'] = $value; $atts['data-maximum-value'] = $maxlength; $atts['data-minimum-value'] = $minlength; $atts = wpcf7_format_atts($atts); $html = sprintf('<span %1$s>%2$s</span>', $atts, $value); return $html; }
function wpcf7dtx_dynamictext_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, 'wpcf7dtx-dynamictext'); if ($validation_error) { $class .= ' wpcf7-not-valid'; } $atts = array(); $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['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); $scval = do_shortcode('[' . $value . ']'); if ($scval != '[' . $value . ']') { $value = esc_attr($scval); } $atts['value'] = $value; //echo '<pre>'; print_r( $tag ); echo '</pre>'; switch ($tag->basetype) { case 'dynamictext': $atts['type'] = 'text'; break; case 'dynamichidden': $atts['type'] = 'hidden'; break; default: $atts['type'] = 'text'; break; } $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 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; }
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['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); $atts['autocomplete'] = $tag->get_option('autocomplete', '[-0-9a-zA-Z]+', 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; }
function wpcf7_quiz_shortcode_handler($tag) { $tag = new WPCF7_Shortcode($tag); if (empty($tag->name)) { return ''; } $validation_error = wpcf7_get_validation_error($tag->name); $class = wpcf7_form_controls_class($tag->type); if ($validation_error) { $class .= ' wpcf7-not-valid'; } $atts = array(); $atts['size'] = $tag->get_size_option('40'); $atts['maxlength'] = $tag->get_maxlength_option(); $atts['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); $atts['autocomplete'] = 'off'; $atts['aria-required'] = 'true'; $atts['aria-invalid'] = $validation_error ? 'true' : 'false'; $pipes = $tag->pipes; if ($pipes instanceof WPCF7_Pipes && !$pipes->zero()) { $pipe = $pipes->random_pipe(); $question = $pipe->before; $answer = $pipe->after; } else { // default quiz $question = '1+1=?'; $answer = '2'; } $answer = wpcf7_canonicalize($answer); $atts['type'] = 'text'; $atts['name'] = $tag->name; $atts = wpcf7_format_atts($atts); $html = sprintf('<span class="wpcf7-form-control-wrap %1$s"><label><span class="wpcf7-quiz-label">%2$s</span> <input %3$s /></label><input type="hidden" name="_wpcf7_quiz_answer_%4$s" value="%5$s" />%6$s</span>', sanitize_html_class($tag->name), esc_html($question), $atts, $tag->name, wp_hash($answer, 'wpcf7_quiz'), $validation_error); return $html; }
function wpcf7_captcha_shortcode_handler($tag) { $tag = new WPCF7_Shortcode($tag); if ('captchac' == $tag->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.', 'contact-form-7') . '</em>'; } if (empty($tag->name)) { return ''; } $validation_error = wpcf7_get_validation_error($tag->name); $class = wpcf7_form_controls_class($tag->type); if ('captchac' == $tag->type) { // CAPTCHA-Challenge (image) $class .= ' wpcf7-captcha-' . $tag->name; $atts = array(); $atts['class'] = $tag->get_class_option($class); $atts['id'] = $tag->get_id_option(); $op = array('img_size' => array(72, 24), 'base' => array(6, 18), 'font_size' => 14, 'font_char_width' => 15); $op = array_merge($op, wpcf7_captchac_options($tag->options)); if (!($filename = wpcf7_generate_captcha($op))) { return ''; } if (!empty($op['img_size'])) { if (isset($op['img_size'][0])) { $atts['width'] = $op['img_size'][0]; } if (isset($op['img_size'][1])) { $atts['height'] = $op['img_size'][1]; } } $atts['alt'] = 'captcha'; $atts['src'] = wpcf7_captcha_url($filename); $atts = wpcf7_format_atts($atts); $prefix = substr($filename, 0, strrpos($filename, '.')); $html = sprintf('<input type="hidden" name="_wpcf7_captcha_challenge_%1$s" value="%2$s" /><img %3$s />', $tag->name, $prefix, $atts); return $html; } elseif ('captchar' == $tag->type) { // CAPTCHA-Response (input) if ($validation_error) { $class .= ' wpcf7-not-valid'; } $atts = array(); $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); $atts['aria-invalid'] = $validation_error ? 'true' : 'false'; $value = (string) reset($tag->values); if (wpcf7_is_posted()) { $value = ''; } if ($tag->has_option('placeholder') || $tag->has_option('watermark')) { $atts['placeholder'] = $value; $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 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; }
$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, ['email', 'url', 'tel'])) { $class .= ' wpcf7-validates-as-' . $tag->basetype; } if ($validation_error) { $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);
/** * 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; }