akismet
3 years ago
constant-contact
3 years ago
recaptcha
3 years ago
sendinblue
3 years ago
stripe
3 years ago
acceptance.php
3 years ago
checkbox.php
3 years ago
count.php
3 years ago
date.php
3 years ago
disallowed-list.php
4 years ago
doi-helper.php
4 years ago
file.php
3 years ago
flamingo.php
3 years ago
hidden.php
7 years ago
listo.php
9 years ago
number.php
3 years ago
quiz.php
4 years ago
really-simple-captcha.php
3 years ago
reflection.php
3 years ago
response.php
6 years ago
select.php
3 years ago
submit.php
4 years ago
text.php
3 years ago
textarea.php
3 years ago
text.php
325 lines
| 1 | <?php |
| 2 | /** |
| 3 | ** A base module for the following types of tags: |
| 4 | ** [text] and [text*] # Single-line text |
| 5 | ** [email] and [email*] # Email address |
| 6 | ** [url] and [url*] # URL |
| 7 | ** [tel] and [tel*] # Telephone number |
| 8 | **/ |
| 9 | |
| 10 | /* form_tag handler */ |
| 11 | |
| 12 | add_action( 'wpcf7_init', 'wpcf7_add_form_tag_text', 10, 0 ); |
| 13 | |
| 14 | function wpcf7_add_form_tag_text() { |
| 15 | wpcf7_add_form_tag( |
| 16 | array( 'text', 'text*', 'email', 'email*', 'url', 'url*', 'tel', 'tel*' ), |
| 17 | 'wpcf7_text_form_tag_handler', |
| 18 | array( |
| 19 | 'name-attr' => true, |
| 20 | ) |
| 21 | ); |
| 22 | } |
| 23 | |
| 24 | function wpcf7_text_form_tag_handler( $tag ) { |
| 25 | if ( empty( $tag->name ) ) { |
| 26 | return ''; |
| 27 | } |
| 28 | |
| 29 | $validation_error = wpcf7_get_validation_error( $tag->name ); |
| 30 | |
| 31 | $class = wpcf7_form_controls_class( $tag->type, 'wpcf7-text' ); |
| 32 | |
| 33 | if ( in_array( $tag->basetype, array( 'email', 'url', 'tel' ) ) ) { |
| 34 | $class .= ' wpcf7-validates-as-' . $tag->basetype; |
| 35 | } |
| 36 | |
| 37 | if ( $validation_error ) { |
| 38 | $class .= ' wpcf7-not-valid'; |
| 39 | } |
| 40 | |
| 41 | $atts = array(); |
| 42 | |
| 43 | $atts['size'] = $tag->get_size_option( '40' ); |
| 44 | $atts['maxlength'] = $tag->get_maxlength_option(); |
| 45 | $atts['minlength'] = $tag->get_minlength_option(); |
| 46 | |
| 47 | if ( $atts['maxlength'] and $atts['minlength'] |
| 48 | and $atts['maxlength'] < $atts['minlength'] ) { |
| 49 | unset( $atts['maxlength'], $atts['minlength'] ); |
| 50 | } |
| 51 | |
| 52 | $atts['class'] = $tag->get_class_option( $class ); |
| 53 | $atts['id'] = $tag->get_id_option(); |
| 54 | $atts['tabindex'] = $tag->get_option( 'tabindex', 'signed_int', true ); |
| 55 | $atts['readonly'] = $tag->has_option( 'readonly' ); |
| 56 | |
| 57 | $atts['autocomplete'] = $tag->get_option( |
| 58 | 'autocomplete', '[-0-9a-zA-Z]+', true |
| 59 | ); |
| 60 | |
| 61 | if ( $tag->is_required() ) { |
| 62 | $atts['aria-required'] = 'true'; |
| 63 | } |
| 64 | |
| 65 | if ( $validation_error ) { |
| 66 | $atts['aria-invalid'] = 'true'; |
| 67 | $atts['aria-describedby'] = wpcf7_get_validation_error_reference( |
| 68 | $tag->name |
| 69 | ); |
| 70 | } else { |
| 71 | $atts['aria-invalid'] = 'false'; |
| 72 | } |
| 73 | |
| 74 | $value = (string) reset( $tag->values ); |
| 75 | |
| 76 | if ( $tag->has_option( 'placeholder' ) |
| 77 | or $tag->has_option( 'watermark' ) ) { |
| 78 | $atts['placeholder'] = $value; |
| 79 | $value = ''; |
| 80 | } |
| 81 | |
| 82 | $value = $tag->get_default_option( $value ); |
| 83 | |
| 84 | $value = wpcf7_get_hangover( $tag->name, $value ); |
| 85 | |
| 86 | $atts['value'] = $value; |
| 87 | $atts['type'] = $tag->basetype; |
| 88 | $atts['name'] = $tag->name; |
| 89 | |
| 90 | $html = sprintf( |
| 91 | '<span class="wpcf7-form-control-wrap" data-name="%1$s"><input %2$s />%3$s</span>', |
| 92 | esc_attr( $tag->name ), |
| 93 | wpcf7_format_atts( $atts ), |
| 94 | $validation_error |
| 95 | ); |
| 96 | |
| 97 | return $html; |
| 98 | } |
| 99 | |
| 100 | |
| 101 | add_action( |
| 102 | 'wpcf7_swv_create_schema', |
| 103 | 'wpcf7_swv_add_text_rules', |
| 104 | 10, 2 |
| 105 | ); |
| 106 | |
| 107 | function wpcf7_swv_add_text_rules( $schema, $contact_form ) { |
| 108 | $tags = $contact_form->scan_form_tags( array( |
| 109 | 'basetype' => array( 'text', 'email', 'url', 'tel' ), |
| 110 | ) ); |
| 111 | |
| 112 | foreach ( $tags as $tag ) { |
| 113 | if ( $tag->is_required() ) { |
| 114 | $schema->add_rule( |
| 115 | wpcf7_swv_create_rule( 'required', array( |
| 116 | 'field' => $tag->name, |
| 117 | 'error' => wpcf7_get_message( 'invalid_required' ), |
| 118 | ) ) |
| 119 | ); |
| 120 | } |
| 121 | |
| 122 | if ( 'email' === $tag->basetype ) { |
| 123 | $schema->add_rule( |
| 124 | wpcf7_swv_create_rule( 'email', array( |
| 125 | 'field' => $tag->name, |
| 126 | 'error' => wpcf7_get_message( 'invalid_email' ), |
| 127 | ) ) |
| 128 | ); |
| 129 | } |
| 130 | |
| 131 | if ( 'url' === $tag->basetype ) { |
| 132 | $schema->add_rule( |
| 133 | wpcf7_swv_create_rule( 'url', array( |
| 134 | 'field' => $tag->name, |
| 135 | 'error' => wpcf7_get_message( 'invalid_url' ), |
| 136 | ) ) |
| 137 | ); |
| 138 | } |
| 139 | |
| 140 | if ( 'tel' === $tag->basetype ) { |
| 141 | $schema->add_rule( |
| 142 | wpcf7_swv_create_rule( 'tel', array( |
| 143 | 'field' => $tag->name, |
| 144 | 'error' => wpcf7_get_message( 'invalid_tel' ), |
| 145 | ) ) |
| 146 | ); |
| 147 | } |
| 148 | |
| 149 | if ( $minlength = $tag->get_minlength_option() ) { |
| 150 | $schema->add_rule( |
| 151 | wpcf7_swv_create_rule( 'minlength', array( |
| 152 | 'field' => $tag->name, |
| 153 | 'threshold' => absint( $minlength ), |
| 154 | 'error' => wpcf7_get_message( 'invalid_too_short' ), |
| 155 | ) ) |
| 156 | ); |
| 157 | } |
| 158 | |
| 159 | if ( $maxlength = $tag->get_maxlength_option() ) { |
| 160 | $schema->add_rule( |
| 161 | wpcf7_swv_create_rule( 'maxlength', array( |
| 162 | 'field' => $tag->name, |
| 163 | 'threshold' => absint( $maxlength ), |
| 164 | 'error' => wpcf7_get_message( 'invalid_too_long' ), |
| 165 | ) ) |
| 166 | ); |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | |
| 172 | /* Messages */ |
| 173 | |
| 174 | add_filter( 'wpcf7_messages', 'wpcf7_text_messages', 10, 1 ); |
| 175 | |
| 176 | function wpcf7_text_messages( $messages ) { |
| 177 | $messages = array_merge( $messages, array( |
| 178 | 'invalid_email' => array( |
| 179 | 'description' => |
| 180 | __( "Email address that the sender entered is invalid", 'contact-form-7' ), |
| 181 | 'default' => |
| 182 | __( "Please enter an email address.", 'contact-form-7' ), |
| 183 | ), |
| 184 | |
| 185 | 'invalid_url' => array( |
| 186 | 'description' => |
| 187 | __( "URL that the sender entered is invalid", 'contact-form-7' ), |
| 188 | 'default' => |
| 189 | __( "Please enter a URL.", 'contact-form-7' ), |
| 190 | ), |
| 191 | |
| 192 | 'invalid_tel' => array( |
| 193 | 'description' => |
| 194 | __( "Telephone number that the sender entered is invalid", 'contact-form-7' ), |
| 195 | 'default' => |
| 196 | __( "Please enter a telephone number.", 'contact-form-7' ), |
| 197 | ), |
| 198 | ) ); |
| 199 | |
| 200 | return $messages; |
| 201 | } |
| 202 | |
| 203 | |
| 204 | /* Tag generator */ |
| 205 | |
| 206 | add_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_text', 15, 0 ); |
| 207 | |
| 208 | function wpcf7_add_tag_generator_text() { |
| 209 | $tag_generator = WPCF7_TagGenerator::get_instance(); |
| 210 | $tag_generator->add( 'text', __( 'text', 'contact-form-7' ), |
| 211 | 'wpcf7_tag_generator_text' ); |
| 212 | $tag_generator->add( 'email', __( 'email', 'contact-form-7' ), |
| 213 | 'wpcf7_tag_generator_text' ); |
| 214 | $tag_generator->add( 'url', __( 'URL', 'contact-form-7' ), |
| 215 | 'wpcf7_tag_generator_text' ); |
| 216 | $tag_generator->add( 'tel', __( 'tel', 'contact-form-7' ), |
| 217 | 'wpcf7_tag_generator_text' ); |
| 218 | } |
| 219 | |
| 220 | function wpcf7_tag_generator_text( $contact_form, $args = '' ) { |
| 221 | $args = wp_parse_args( $args, array() ); |
| 222 | $type = $args['id']; |
| 223 | |
| 224 | if ( ! in_array( $type, array( 'email', 'url', 'tel' ) ) ) { |
| 225 | $type = 'text'; |
| 226 | } |
| 227 | |
| 228 | if ( 'text' == $type ) { |
| 229 | $description = __( "Generate a form-tag for a single-line plain text input field. For more details, see %s.", 'contact-form-7' ); |
| 230 | } elseif ( 'email' == $type ) { |
| 231 | $description = __( "Generate a form-tag for a single-line email address input field. For more details, see %s.", 'contact-form-7' ); |
| 232 | } elseif ( 'url' == $type ) { |
| 233 | $description = __( "Generate a form-tag for a single-line URL input field. For more details, see %s.", 'contact-form-7' ); |
| 234 | } elseif ( 'tel' == $type ) { |
| 235 | $description = __( "Generate a form-tag for a single-line telephone number input field. For more details, see %s.", 'contact-form-7' ); |
| 236 | } |
| 237 | |
| 238 | $desc_link = wpcf7_link( __( 'https://contactform7.com/text-fields/', 'contact-form-7' ), __( 'Text fields', 'contact-form-7' ) ); |
| 239 | |
| 240 | ?> |
| 241 | <div class="control-box"> |
| 242 | <fieldset> |
| 243 | <legend><?php echo sprintf( esc_html( $description ), $desc_link ); ?></legend> |
| 244 | |
| 245 | <table class="form-table"> |
| 246 | <tbody> |
| 247 | <tr> |
| 248 | <th scope="row"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></th> |
| 249 | <td> |
| 250 | <fieldset> |
| 251 | <legend class="screen-reader-text"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></legend> |
| 252 | <label><input type="checkbox" name="required" /> <?php echo esc_html( __( 'Required field', 'contact-form-7' ) ); ?></label> |
| 253 | </fieldset> |
| 254 | </td> |
| 255 | </tr> |
| 256 | |
| 257 | <tr> |
| 258 | <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?></label></th> |
| 259 | <td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td> |
| 260 | </tr> |
| 261 | |
| 262 | <tr> |
| 263 | <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-values' ); ?>"><?php echo esc_html( __( 'Default value', 'contact-form-7' ) ); ?></label></th> |
| 264 | <td><input type="text" name="values" class="oneline" id="<?php echo esc_attr( $args['content'] . '-values' ); ?>" /><br /> |
| 265 | <label><input type="checkbox" name="placeholder" class="option" /> <?php echo esc_html( __( 'Use this text as the placeholder of the field', 'contact-form-7' ) ); ?></label></td> |
| 266 | </tr> |
| 267 | |
| 268 | <?php if ( in_array( $type, array( 'text', 'email', 'url' ) ) ) : ?> |
| 269 | <tr> |
| 270 | <th scope="row"><?php echo esc_html( __( 'Akismet', 'contact-form-7' ) ); ?></th> |
| 271 | <td> |
| 272 | <fieldset> |
| 273 | <legend class="screen-reader-text"><?php echo esc_html( __( 'Akismet', 'contact-form-7' ) ); ?></legend> |
| 274 | |
| 275 | <?php if ( 'text' == $type ) : ?> |
| 276 | <label> |
| 277 | <input type="checkbox" name="akismet:author" class="option" /> |
| 278 | <?php echo esc_html( __( "This field requires author's name", 'contact-form-7' ) ); ?> |
| 279 | </label> |
| 280 | <?php elseif ( 'email' == $type ) : ?> |
| 281 | <label> |
| 282 | <input type="checkbox" name="akismet:author_email" class="option" /> |
| 283 | <?php echo esc_html( __( "This field requires author's email address", 'contact-form-7' ) ); ?> |
| 284 | </label> |
| 285 | <?php elseif ( 'url' == $type ) : ?> |
| 286 | <label> |
| 287 | <input type="checkbox" name="akismet:author_url" class="option" /> |
| 288 | <?php echo esc_html( __( "This field requires author's URL", 'contact-form-7' ) ); ?> |
| 289 | </label> |
| 290 | <?php endif; ?> |
| 291 | |
| 292 | </fieldset> |
| 293 | </td> |
| 294 | </tr> |
| 295 | <?php endif; ?> |
| 296 | |
| 297 | <tr> |
| 298 | <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'contact-form-7' ) ); ?></label></th> |
| 299 | <td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-id' ); ?>" /></td> |
| 300 | </tr> |
| 301 | |
| 302 | <tr> |
| 303 | <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'contact-form-7' ) ); ?></label></th> |
| 304 | <td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" /></td> |
| 305 | </tr> |
| 306 | |
| 307 | </tbody> |
| 308 | </table> |
| 309 | </fieldset> |
| 310 | </div> |
| 311 | |
| 312 | <div class="insert-box"> |
| 313 | <input type="text" name="<?php echo $type; ?>" class="tag code" readonly="readonly" onfocus="this.select()" /> |
| 314 | |
| 315 | <div class="submitbox"> |
| 316 | <input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" /> |
| 317 | </div> |
| 318 | |
| 319 | <br class="clear" /> |
| 320 | |
| 321 | <p class="description mail-tag"><label for="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>"><?php echo sprintf( esc_html( __( "To use the value input through this field in a mail field, you need to insert the corresponding mail-tag (%s) into the field on the Mail tab.", 'contact-form-7' ) ), '<strong><span class="mail-tag"></span></strong>' ); ?><input type="text" class="mail-tag code hidden" readonly="readonly" id="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>" /></label></p> |
| 322 | </div> |
| 323 | <?php |
| 324 | } |
| 325 |