WPCF7_Validation

The Contact Form 7 WPCF7 Validation class.

Defined (1)

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

/includes/validation.php  
  1. class WPCF7_Validation implements ArrayAccess { 
  2. private $invalid_fields = array(); 
  3. private $container = array(); 
  4.  
  5. public function __construct() { 
  6. $this->container = array( 
  7. 'valid' => true,  
  8. 'reason' => array(),  
  9. 'idref' => array(),  
  10. ); 
  11.  
  12. public function invalidate( $context, $message ) { 
  13. if ( $context instanceof WPCF7_FormTag ) { 
  14. $tag = $context; 
  15. } elseif ( is_array( $context ) ) { 
  16. $tag = new WPCF7_FormTag( $context ); 
  17. } elseif ( is_string( $context ) ) { 
  18. $tags = wpcf7_scan_form_tags( array( 'name' => trim( $context ) ) ); 
  19. $tag = $tags ? new WPCF7_FormTag( $tags[0] ) : null; 
  20.  
  21. $name = ! empty( $tag ) ? $tag->name : null; 
  22.  
  23. if ( empty( $name ) || ! wpcf7_is_name( $name ) ) { 
  24. return; 
  25.  
  26. if ( $this->is_valid( $name ) ) { 
  27. $id = $tag->get_id_option(); 
  28.  
  29. if ( empty( $id ) || ! wpcf7_is_name( $id ) ) { 
  30. $id = null; 
  31.  
  32. $this->invalid_fields[$name] = array( 
  33. 'reason' => (string) $message,  
  34. 'idref' => $id,  
  35. ); 
  36.  
  37. public function is_valid( $name = null ) { 
  38. if ( ! empty( $name ) ) { 
  39. return ! isset( $this->invalid_fields[$name] ); 
  40. } else { 
  41. return empty( $this->invalid_fields ); 
  42.  
  43. public function get_invalid_fields() { 
  44. return $this->invalid_fields; 
  45.  
  46. public function offsetSet( $offset, $value ) { 
  47. if ( isset( $this->container[$offset] ) ) { 
  48. $this->container[$offset] = $value; 
  49.  
  50. if ( 'reason' == $offset && is_array( $value ) ) { 
  51. foreach ( $value as $k => $v ) { 
  52. $this->invalidate( $k, $v ); 
  53.  
  54. public function offsetGet( $offset ) { 
  55. if ( isset( $this->container[$offset] ) ) { 
  56. return $this->container[$offset]; 
  57.  
  58. public function offsetExists( $offset ) { 
  59. return isset( $this->container[$offset] ); 
  60.  
  61. public function offsetUnset( $offset ) {