wpcf7dtx_dynamictext_validation_filter

The Contact Form 7 - Dynamic Text Extension wpcf7dtx dynamictext validation filter function.

Description

wpcf7dtx_dynamictext_validation_filter( $result, $tag ); 

Parameters (2)

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

Usage

  1. if ( !function_exists( 'wpcf7dtx_dynamictext_validation_filter' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'contact-form-7-dynamic-text-extension/contact-form-7-dynamic-text-extension.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 = wpcf7dtx_dynamictext_validation_filter($result, $tag); 
  12.  

Defined (1)

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

/contact-form-7-dynamic-text-extension.php  
  1. function wpcf7dtx_dynamictext_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 ( 'dynamictext' == $tag->basetype ) { 
  11. if ( $tag->is_required() && '' == $value ) { 
  12. $result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) ); 
  13.  
  14. if ( ! empty( $value ) ) { 
  15. $maxlength = $tag->get_maxlength_option(); 
  16. $minlength = $tag->get_minlength_option(); 
  17.  
  18. if ( $maxlength && $minlength && $maxlength < $minlength ) { 
  19. $maxlength = $minlength = null; 
  20.  
  21. $code_units = wpcf7_count_code_units( $value ); 
  22.  
  23. if ( false !== $code_units ) { 
  24. if ( $maxlength && $maxlength < $code_units ) { 
  25. $result->invalidate( $tag, wpcf7_get_message( 'invalid_too_long' ) ); 
  26. } elseif ( $minlength && $code_units < $minlength ) { 
  27. $result->invalidate( $tag, wpcf7_get_message( 'invalid_too_short' ) ); 
  28.  
  29. return $result;