wpcf7_quiz_validation_filter

The Contact Form 7 wpcf7 quiz validation filter function.

Description

wpcf7_quiz_validation_filter( $result, $tag ); 

Parameters (2)

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

Usage

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

Defined (1)

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

/modules/quiz.php  
  1. function wpcf7_quiz_validation_filter( $result, $tag ) { 
  2. $tag = new WPCF7_FormTag( $tag ); 
  3.  
  4. $name = $tag->name; 
  5.  
  6. $answer = isset( $_POST[$name] ) ? wpcf7_canonicalize( $_POST[$name] ) : ''; 
  7. $answer = wp_unslash( $answer ); 
  8.  
  9. $answer_hash = wp_hash( $answer, 'wpcf7_quiz' ); 
  10.  
  11. $expected_hash = isset( $_POST['_wpcf7_quiz_answer_' . $name] ) 
  12. ? (string) $_POST['_wpcf7_quiz_answer_' . $name] 
  13. : ''; 
  14.  
  15. if ( $answer_hash != $expected_hash ) { 
  16. $result->invalidate( $tag, wpcf7_get_message( 'quiz_answer_not_correct' ) ); 
  17.  
  18. return $result;