akismet
1 year ago
constant-contact
1 year ago
recaptcha
1 year ago
sendinblue
1 year ago
stripe
1 year ago
acceptance.php
1 year ago
checkbox.php
1 year ago
count.php
1 year ago
date.php
1 year ago
disallowed-list.php
1 year ago
doi-helper.php
4 years ago
file.php
1 year ago
flamingo.php
1 year ago
hidden.php
7 years ago
listo.php
2 years ago
number.php
1 year ago
quiz.php
1 year ago
really-simple-captcha.php
1 year ago
reflection.php
3 years ago
response.php
6 years ago
select.php
1 year ago
submit.php
1 year ago
text.php
1 year ago
textarea.php
1 year ago
textarea.php
215 lines
| 1 | <?php |
| 2 | /** |
| 3 | ** A base module for [textarea] and [textarea*] |
| 4 | **/ |
| 5 | |
| 6 | /* form_tag handler */ |
| 7 | |
| 8 | add_action( 'wpcf7_init', 'wpcf7_add_form_tag_textarea', 10, 0 ); |
| 9 | |
| 10 | function wpcf7_add_form_tag_textarea() { |
| 11 | wpcf7_add_form_tag( array( 'textarea', 'textarea*' ), |
| 12 | 'wpcf7_textarea_form_tag_handler', array( 'name-attr' => true ) |
| 13 | ); |
| 14 | } |
| 15 | |
| 16 | function wpcf7_textarea_form_tag_handler( $tag ) { |
| 17 | if ( empty( $tag->name ) ) { |
| 18 | return ''; |
| 19 | } |
| 20 | |
| 21 | $validation_error = wpcf7_get_validation_error( $tag->name ); |
| 22 | |
| 23 | $class = wpcf7_form_controls_class( $tag->type ); |
| 24 | |
| 25 | if ( $validation_error ) { |
| 26 | $class .= ' wpcf7-not-valid'; |
| 27 | } |
| 28 | |
| 29 | $atts = array(); |
| 30 | |
| 31 | $atts['cols'] = $tag->get_cols_option( '40' ); |
| 32 | $atts['rows'] = $tag->get_rows_option( '10' ); |
| 33 | $atts['maxlength'] = $tag->get_maxlength_option( '2000' ); |
| 34 | $atts['minlength'] = $tag->get_minlength_option(); |
| 35 | |
| 36 | if ( $atts['maxlength'] and $atts['minlength'] |
| 37 | and $atts['maxlength'] < $atts['minlength'] ) { |
| 38 | unset( $atts['maxlength'], $atts['minlength'] ); |
| 39 | } |
| 40 | |
| 41 | $atts['class'] = $tag->get_class_option( $class ); |
| 42 | $atts['id'] = $tag->get_id_option(); |
| 43 | $atts['tabindex'] = $tag->get_option( 'tabindex', 'signed_int', true ); |
| 44 | $atts['readonly'] = $tag->has_option( 'readonly' ); |
| 45 | |
| 46 | $atts['autocomplete'] = $tag->get_option( |
| 47 | 'autocomplete', '[-0-9a-zA-Z]+', true |
| 48 | ); |
| 49 | |
| 50 | if ( $tag->is_required() ) { |
| 51 | $atts['aria-required'] = 'true'; |
| 52 | } |
| 53 | |
| 54 | if ( $validation_error ) { |
| 55 | $atts['aria-invalid'] = 'true'; |
| 56 | $atts['aria-describedby'] = wpcf7_get_validation_error_reference( |
| 57 | $tag->name |
| 58 | ); |
| 59 | } else { |
| 60 | $atts['aria-invalid'] = 'false'; |
| 61 | } |
| 62 | |
| 63 | $value = empty( $tag->content ) |
| 64 | ? (string) reset( $tag->values ) |
| 65 | : $tag->content; |
| 66 | |
| 67 | if ( $tag->has_option( 'placeholder' ) |
| 68 | or $tag->has_option( 'watermark' ) ) { |
| 69 | $atts['placeholder'] = $value; |
| 70 | $value = ''; |
| 71 | } |
| 72 | |
| 73 | $value = $tag->get_default_option( $value ); |
| 74 | |
| 75 | $value = wpcf7_get_hangover( $tag->name, $value ); |
| 76 | |
| 77 | $atts['name'] = $tag->name; |
| 78 | |
| 79 | $html = sprintf( |
| 80 | '<span class="wpcf7-form-control-wrap" data-name="%1$s"><textarea %2$s>%3$s</textarea>%4$s</span>', |
| 81 | esc_attr( $tag->name ), |
| 82 | wpcf7_format_atts( $atts ), |
| 83 | esc_textarea( $value ), |
| 84 | $validation_error |
| 85 | ); |
| 86 | |
| 87 | return $html; |
| 88 | } |
| 89 | |
| 90 | |
| 91 | add_action( |
| 92 | 'wpcf7_swv_create_schema', |
| 93 | 'wpcf7_swv_add_textarea_rules', |
| 94 | 10, 2 |
| 95 | ); |
| 96 | |
| 97 | function wpcf7_swv_add_textarea_rules( $schema, $contact_form ) { |
| 98 | $tags = $contact_form->scan_form_tags( array( |
| 99 | 'basetype' => array( 'textarea' ), |
| 100 | ) ); |
| 101 | |
| 102 | foreach ( $tags as $tag ) { |
| 103 | if ( $tag->is_required() ) { |
| 104 | $schema->add_rule( |
| 105 | wpcf7_swv_create_rule( 'required', array( |
| 106 | 'field' => $tag->name, |
| 107 | 'error' => wpcf7_get_message( 'invalid_required' ), |
| 108 | ) ) |
| 109 | ); |
| 110 | } |
| 111 | |
| 112 | if ( $minlength = $tag->get_minlength_option() ) { |
| 113 | $schema->add_rule( |
| 114 | wpcf7_swv_create_rule( 'minlength', array( |
| 115 | 'field' => $tag->name, |
| 116 | 'threshold' => absint( $minlength ), |
| 117 | 'error' => wpcf7_get_message( 'invalid_too_short' ), |
| 118 | ) ) |
| 119 | ); |
| 120 | } |
| 121 | |
| 122 | if ( $maxlength = $tag->get_maxlength_option( '2000' ) ) { |
| 123 | $schema->add_rule( |
| 124 | wpcf7_swv_create_rule( 'maxlength', array( |
| 125 | 'field' => $tag->name, |
| 126 | 'threshold' => absint( $maxlength ), |
| 127 | 'error' => wpcf7_get_message( 'invalid_too_long' ), |
| 128 | ) ) |
| 129 | ); |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | |
| 135 | /* Tag generator */ |
| 136 | |
| 137 | add_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_textarea', 20, 0 ); |
| 138 | |
| 139 | function wpcf7_add_tag_generator_textarea() { |
| 140 | $tag_generator = WPCF7_TagGenerator::get_instance(); |
| 141 | |
| 142 | $tag_generator->add( 'textarea', |
| 143 | __( 'text area', 'contact-form-7' ), |
| 144 | 'wpcf7_tag_generator_textarea', |
| 145 | array( 'version' => '2' ) |
| 146 | ); |
| 147 | } |
| 148 | |
| 149 | function wpcf7_tag_generator_textarea( $contact_form, $options ) { |
| 150 | $field_types = array( |
| 151 | 'textarea' => array( |
| 152 | 'display_name' => __( 'Text area', 'contact-form-7' ), |
| 153 | 'heading' => __( 'Text area form-tag generator', 'contact-form-7' ), |
| 154 | 'description' => __( 'Generates a form-tag for a <a href="https://contactform7.com/text-fields/">multi-line plain text input area</a>.', 'contact-form-7' ), |
| 155 | ), |
| 156 | ); |
| 157 | |
| 158 | $tgg = new WPCF7_TagGeneratorGenerator( $options['content'] ); |
| 159 | |
| 160 | ?> |
| 161 | <header class="description-box"> |
| 162 | <h3><?php |
| 163 | echo esc_html( $field_types['textarea']['heading'] ); |
| 164 | ?></h3> |
| 165 | |
| 166 | <p><?php |
| 167 | $description = wp_kses( |
| 168 | $field_types['textarea']['description'], |
| 169 | array( |
| 170 | 'a' => array( 'href' => true ), |
| 171 | 'strong' => array(), |
| 172 | ), |
| 173 | array( 'http', 'https' ) |
| 174 | ); |
| 175 | |
| 176 | echo $description; |
| 177 | ?></p> |
| 178 | </header> |
| 179 | |
| 180 | <div class="control-box"> |
| 181 | <?php |
| 182 | $tgg->print( 'field_type', array( |
| 183 | 'with_required' => true, |
| 184 | 'select_options' => array( |
| 185 | 'textarea' => $field_types['textarea']['display_name'], |
| 186 | ), |
| 187 | ) ); |
| 188 | |
| 189 | $tgg->print( 'field_name' ); |
| 190 | |
| 191 | $tgg->print( 'class_attr' ); |
| 192 | |
| 193 | $tgg->print( 'min_max', array( |
| 194 | 'title' => __( 'Length', 'contact-form-7' ), |
| 195 | 'min_option' => 'minlength:', |
| 196 | 'max_option' => 'maxlength:', |
| 197 | ) ); |
| 198 | |
| 199 | $tgg->print( 'default_value', array( |
| 200 | 'with_placeholder' => true, |
| 201 | 'use_content' => true, |
| 202 | ) ); |
| 203 | ?> |
| 204 | </div> |
| 205 | |
| 206 | <footer class="insert-box"> |
| 207 | <?php |
| 208 | $tgg->print( 'insert_box_content' ); |
| 209 | |
| 210 | $tgg->print( 'mail_tag_tip' ); |
| 211 | ?> |
| 212 | </footer> |
| 213 | <?php |
| 214 | } |
| 215 |