acceptance.php
11 years ago
akismet.php
11 years ago
captcha.php
11 years ago
checkbox.php
11 years ago
date.php
11 years ago
file.php
11 years ago
flamingo.php
11 years ago
jetpack.php
12 years ago
listo.php
12 years ago
number.php
11 years ago
quiz.php
11 years ago
response.php
11 years ago
select.php
11 years ago
submit.php
11 years ago
text.php
11 years ago
textarea.php
11 years ago
textarea.php
158 lines
| 1 | <?php |
| 2 | /** |
| 3 | ** A base module for [textarea] and [textarea*] |
| 4 | **/ |
| 5 | |
| 6 | /* Shortcode handler */ |
| 7 | |
| 8 | add_action( 'wpcf7_init', 'wpcf7_add_shortcode_textarea' ); |
| 9 | |
| 10 | function wpcf7_add_shortcode_textarea() { |
| 11 | wpcf7_add_shortcode( array( 'textarea', 'textarea*' ), |
| 12 | 'wpcf7_textarea_shortcode_handler', true ); |
| 13 | } |
| 14 | |
| 15 | function wpcf7_textarea_shortcode_handler( $tag ) { |
| 16 | $tag = new WPCF7_Shortcode( $tag ); |
| 17 | |
| 18 | if ( empty( $tag->name ) ) |
| 19 | return ''; |
| 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 | $atts = array(); |
| 29 | |
| 30 | $atts['cols'] = $tag->get_cols_option( '40' ); |
| 31 | $atts['rows'] = $tag->get_rows_option( '10' ); |
| 32 | $atts['maxlength'] = $tag->get_maxlength_option(); |
| 33 | $atts['class'] = $tag->get_class_option( $class ); |
| 34 | $atts['id'] = $tag->get_id_option(); |
| 35 | $atts['tabindex'] = $tag->get_option( 'tabindex', 'int', true ); |
| 36 | |
| 37 | if ( $tag->has_option( 'readonly' ) ) |
| 38 | $atts['readonly'] = 'readonly'; |
| 39 | |
| 40 | if ( $tag->is_required() ) |
| 41 | $atts['aria-required'] = 'true'; |
| 42 | |
| 43 | $atts['aria-invalid'] = $validation_error ? 'true' : 'false'; |
| 44 | |
| 45 | $value = (string) reset( $tag->values ); |
| 46 | |
| 47 | if ( '' !== $tag->content ) |
| 48 | $value = $tag->content; |
| 49 | |
| 50 | if ( $tag->has_option( 'placeholder' ) || $tag->has_option( 'watermark' ) ) { |
| 51 | $atts['placeholder'] = $value; |
| 52 | $value = ''; |
| 53 | } |
| 54 | |
| 55 | $value = wpcf7_get_hangover( $tag->name, $value ); |
| 56 | |
| 57 | $atts['name'] = $tag->name; |
| 58 | |
| 59 | $atts = wpcf7_format_atts( $atts ); |
| 60 | |
| 61 | $html = sprintf( |
| 62 | '<span class="wpcf7-form-control-wrap %1$s"><textarea %2$s>%3$s</textarea>%4$s</span>', |
| 63 | sanitize_html_class( $tag->name ), $atts, |
| 64 | esc_textarea( $value ), $validation_error ); |
| 65 | |
| 66 | return $html; |
| 67 | } |
| 68 | |
| 69 | |
| 70 | /* Validation filter */ |
| 71 | |
| 72 | add_filter( 'wpcf7_validate_textarea', 'wpcf7_textarea_validation_filter', 10, 2 ); |
| 73 | add_filter( 'wpcf7_validate_textarea*', 'wpcf7_textarea_validation_filter', 10, 2 ); |
| 74 | |
| 75 | function wpcf7_textarea_validation_filter( $result, $tag ) { |
| 76 | $tag = new WPCF7_Shortcode( $tag ); |
| 77 | |
| 78 | $type = $tag->type; |
| 79 | $name = $tag->name; |
| 80 | |
| 81 | $value = isset( $_POST[$name] ) ? (string) $_POST[$name] : ''; |
| 82 | |
| 83 | if ( 'textarea*' == $type ) { |
| 84 | if ( '' == $value ) { |
| 85 | $result['valid'] = false; |
| 86 | $result['reason'][$name] = wpcf7_get_message( 'invalid_required' ); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | if ( isset( $result['reason'][$name] ) && $id = $tag->get_id_option() ) { |
| 91 | $result['idref'][$name] = $id; |
| 92 | } |
| 93 | |
| 94 | return $result; |
| 95 | } |
| 96 | |
| 97 | |
| 98 | /* Tag generator */ |
| 99 | |
| 100 | add_action( 'admin_init', 'wpcf7_add_tag_generator_textarea', 20 ); |
| 101 | |
| 102 | function wpcf7_add_tag_generator_textarea() { |
| 103 | if ( ! function_exists( 'wpcf7_add_tag_generator' ) ) |
| 104 | return; |
| 105 | |
| 106 | wpcf7_add_tag_generator( 'textarea', __( 'Text area', 'contact-form-7' ), |
| 107 | 'wpcf7-tg-pane-textarea', 'wpcf7_tg_pane_textarea' ); |
| 108 | } |
| 109 | |
| 110 | function wpcf7_tg_pane_textarea( $contact_form ) { |
| 111 | ?> |
| 112 | <div id="wpcf7-tg-pane-textarea" class="hidden"> |
| 113 | <form action=""> |
| 114 | <table> |
| 115 | <tr><td><input type="checkbox" name="required" /> <?php echo esc_html( __( 'Required field?', 'contact-form-7' ) ); ?></td></tr> |
| 116 | <tr><td><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?><br /><input type="text" name="name" class="tg-name oneline" /></td><td></td></tr> |
| 117 | </table> |
| 118 | |
| 119 | <table> |
| 120 | <tr> |
| 121 | <td><code>id</code> (<?php echo esc_html( __( 'optional', 'contact-form-7' ) ); ?>)<br /> |
| 122 | <input type="text" name="id" class="idvalue oneline option" /></td> |
| 123 | |
| 124 | <td><code>class</code> (<?php echo esc_html( __( 'optional', 'contact-form-7' ) ); ?>)<br /> |
| 125 | <input type="text" name="class" class="classvalue oneline option" /></td> |
| 126 | </tr> |
| 127 | |
| 128 | <tr> |
| 129 | <td><code>cols</code> (<?php echo esc_html( __( 'optional', 'contact-form-7' ) ); ?>)<br /> |
| 130 | <input type="number" name="cols" class="numeric oneline option" min="1" /></td> |
| 131 | |
| 132 | <td><code>rows</code> (<?php echo esc_html( __( 'optional', 'contact-form-7' ) ); ?>)<br /> |
| 133 | <input type="number" name="rows" class="numeric oneline option" min="1" /></td> |
| 134 | </tr> |
| 135 | |
| 136 | <tr> |
| 137 | <td><code>maxlength</code> (<?php echo esc_html( __( 'optional', 'contact-form-7' ) ); ?>)<br /> |
| 138 | <input type="number" name="maxlength" class="numeric oneline option" min="1" /></td> |
| 139 | </tr> |
| 140 | |
| 141 | <tr> |
| 142 | <td><?php echo esc_html( __( 'Default value', 'contact-form-7' ) ); ?> (<?php echo esc_html( __( 'optional', 'contact-form-7' ) ); ?>)<br /><input type="text" name="values" class="oneline" /></td> |
| 143 | |
| 144 | <td> |
| 145 | <br /><input type="checkbox" name="placeholder" class="option" /> <?php echo esc_html( __( 'Use this text as placeholder?', 'contact-form-7' ) ); ?> |
| 146 | </td> |
| 147 | </tr> |
| 148 | </table> |
| 149 | |
| 150 | <div class="tg-tag"><?php echo esc_html( __( "Copy this code and paste it into the form left.", 'contact-form-7' ) ); ?><br /><input type="text" name="textarea" class="tag wp-ui-text-highlight code" readonly="readonly" onfocus="this.select()" /></div> |
| 151 | |
| 152 | <div class="tg-mail-tag"><?php echo esc_html( __( "And, put this code into the Mail fields below.", 'contact-form-7' ) ); ?><br /><input type="text" class="mail-tag wp-ui-text-highlight code" readonly="readonly" onfocus="this.select()" /></div> |
| 153 | </form> |
| 154 | </div> |
| 155 | <?php |
| 156 | } |
| 157 | |
| 158 | ?> |