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_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; }
/** * 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; }