wpcf7_number_validation_filter

The Contact Form 7 wpcf7 number validation filter function.

Description

wpcf7_number_validation_filter( $result, $tag ); 

Parameters (2)

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

Usage

  1. if ( !function_exists( 'wpcf7_number_validation_filter' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'contact-form-7/modules/number.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_number_validation_filter($result, $tag); 
  12.  

Defined (1)

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

/modules/number.php  
  1. function wpcf7_number_validation_filter( $result, $tag ) { 
  2. $tag = new WPCF7_FormTag( $tag ); 
  3.  
  4. $name = $tag->name; 
  5.  
  6. $value = isset( $_POST[$name] ) 
  7. ? trim( strtr( (string) $_POST[$name], "\n", " " ) ) 
  8. : ''; 
  9.  
  10. $min = $tag->get_option( 'min', 'signed_int', true ); 
  11. $max = $tag->get_option( 'max', 'signed_int', true ); 
  12.  
  13. if ( $tag->is_required() && '' == $value ) { 
  14. $result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) ); 
  15. } elseif ( '' != $value && ! wpcf7_is_number( $value ) ) { 
  16. $result->invalidate( $tag, wpcf7_get_message( 'invalid_number' ) ); 
  17. } elseif ( '' != $value && '' != $min && (float) $value < (float) $min ) { 
  18. $result->invalidate( $tag, wpcf7_get_message( 'number_too_small' ) ); 
  19. } elseif ( '' != $value && '' != $max && (float) $max < (float) $value ) { 
  20. $result->invalidate( $tag, wpcf7_get_message( 'number_too_large' ) ); 
  21.  
  22. return $result;