wpcf7_text_form_tag_handler

The Contact Form 7 wpcf7 text form tag handler function.

Description

wpcf7_text_form_tag_handler( $tag ); 

Parameters (1)

0. $tag
The tag.

Usage

  1. if ( !function_exists( 'wpcf7_text_form_tag_handler' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'contact-form-7/modules/text.php'; 
  3.  
  4. // The tag. 
  5. $tag = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wpcf7_text_form_tag_handler($tag); 
  9.  

Defined (1)

The function is defined in the following location(s).

/modules/text.php  
  1. function wpcf7_text_form_tag_handler( $tag ) { 
  2. $tag = new WPCF7_FormTag( $tag ); 
  3.  
  4. if ( empty( $tag->name ) ) { 
  5. return ''; 
  6.  
  7. $validation_error = wpcf7_get_validation_error( $tag->name ); 
  8.  
  9. $class = wpcf7_form_controls_class( $tag->type, 'wpcf7-text' ); 
  10.  
  11. if ( in_array( $tag->basetype, array( 'email', 'url', 'tel' ) ) ) { 
  12. $class .= ' wpcf7-validates-as-' . $tag->basetype; 
  13.  
  14. if ( $validation_error ) { 
  15. $class .= ' wpcf7-not-valid'; 
  16.  
  17. $atts = array(); 
  18.  
  19. $atts['size'] = $tag->get_size_option( '40' ); 
  20. $atts['maxlength'] = $tag->get_maxlength_option(); 
  21. $atts['minlength'] = $tag->get_minlength_option(); 
  22.  
  23. if ( $atts['maxlength'] && $atts['minlength'] 
  24. && $atts['maxlength'] < $atts['minlength'] ) { 
  25. unset( $atts['maxlength'], $atts['minlength'] ); 
  26.  
  27. $atts['class'] = $tag->get_class_option( $class ); 
  28. $atts['id'] = $tag->get_id_option(); 
  29. $atts['tabindex'] = $tag->get_option( 'tabindex', 'int', true ); 
  30.  
  31. $atts['autocomplete'] = $tag->get_option( 'autocomplete',  
  32. '[-0-9a-zA-Z]+', true ); 
  33.  
  34. if ( $tag->has_option( 'readonly' ) ) { 
  35. $atts['readonly'] = 'readonly'; 
  36.  
  37. if ( $tag->is_required() ) { 
  38. $atts['aria-required'] = 'true'; 
  39.  
  40. $atts['aria-invalid'] = $validation_error ? 'true' : 'false'; 
  41.  
  42. $value = (string) reset( $tag->values ); 
  43.  
  44. if ( $tag->has_option( 'placeholder' ) || $tag->has_option( 'watermark' ) ) { 
  45. $atts['placeholder'] = $value; 
  46. $value = ''; 
  47.  
  48. $value = $tag->get_default_option( $value ); 
  49.  
  50. $value = wpcf7_get_hangover( $tag->name, $value ); 
  51.  
  52. $atts['value'] = $value; 
  53.  
  54. if ( wpcf7_support_html5() ) { 
  55. $atts['type'] = $tag->basetype; 
  56. } else { 
  57. $atts['type'] = 'text'; 
  58.  
  59. $atts['name'] = $tag->name; 
  60.  
  61. $atts = wpcf7_format_atts( $atts ); 
  62.  
  63. $html = sprintf( 
  64. '<span class="wpcf7-form-control-wrap %1$s"><input %2$s />%3$s</span>',  
  65. sanitize_html_class( $tag->name ), $atts, $validation_error ); 
  66.  
  67. return $html;