wpcf7_text_validation_filter

The Contact Form 7 wpcf7 text validation filter function.

Description

wpcf7_text_validation_filter( $result, $tag ); 

Parameters (2)

0. $result
The result.
1. $tag
The tag.

Usage

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

Defined (1)

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

/modules/text.php  
  1. function wpcf7_text_validation_filter( $result, $tag ) { 
  2. $tag = new WPCF7_FormTag( $tag ); 
  3.  
  4. $name = $tag->name; 
  5.  
  6. $value = isset( $_POST[$name] ) 
  7. ? trim( wp_unslash( strtr( (string) $_POST[$name], "\n", " " ) ) ) 
  8. : ''; 
  9.  
  10. if ( 'text' == $tag->basetype ) { 
  11. if ( $tag->is_required() && '' == $value ) { 
  12. $result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) ); 
  13.  
  14. if ( 'email' == $tag->basetype ) { 
  15. if ( $tag->is_required() && '' == $value ) { 
  16. $result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) ); 
  17. } elseif ( '' != $value && ! wpcf7_is_email( $value ) ) { 
  18. $result->invalidate( $tag, wpcf7_get_message( 'invalid_email' ) ); 
  19.  
  20. if ( 'url' == $tag->basetype ) { 
  21. if ( $tag->is_required() && '' == $value ) { 
  22. $result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) ); 
  23. } elseif ( '' != $value && ! wpcf7_is_url( $value ) ) { 
  24. $result->invalidate( $tag, wpcf7_get_message( 'invalid_url' ) ); 
  25.  
  26. if ( 'tel' == $tag->basetype ) { 
  27. if ( $tag->is_required() && '' == $value ) { 
  28. $result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) ); 
  29. } elseif ( '' != $value && ! wpcf7_is_tel( $value ) ) { 
  30. $result->invalidate( $tag, wpcf7_get_message( 'invalid_tel' ) ); 
  31.  
  32. if ( '' !== $value ) { 
  33. $maxlength = $tag->get_maxlength_option(); 
  34. $minlength = $tag->get_minlength_option(); 
  35.  
  36. if ( $maxlength && $minlength && $maxlength < $minlength ) { 
  37. $maxlength = $minlength = null; 
  38.  
  39. $code_units = wpcf7_count_code_units( stripslashes( $value ) ); 
  40.  
  41. if ( false !== $code_units ) { 
  42. if ( $maxlength && $maxlength < $code_units ) { 
  43. $result->invalidate( $tag, wpcf7_get_message( 'invalid_too_long' ) ); 
  44. } elseif ( $minlength && $code_units < $minlength ) { 
  45. $result->invalidate( $tag, wpcf7_get_message( 'invalid_too_short' ) ); 
  46.  
  47. return $result;