wpcf7_quiz_form_tag_handler

The Contact Form 7 wpcf7 quiz form tag handler function.

Description

wpcf7_quiz_form_tag_handler( $tag ); 

Parameters (1)

0. $tag
The tag.

Usage

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

Defined (1)

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

/modules/quiz.php  
  1. function wpcf7_quiz_form_tag_handler( $tag ) { 
  2. $tag = new WPCF7_FormTag( $tag ); 
  3.  
  4. if ( empty( $tag->name ) ) { 
  5. return ''; 
  6.  
  7. $validation_error = wpcf7_get_validation_error( $tag->name ); 
  8.  
  9. $class = wpcf7_form_controls_class( $tag->type ); 
  10.  
  11. if ( $validation_error ) { 
  12. $class .= ' wpcf7-not-valid'; 
  13.  
  14. $atts = array(); 
  15.  
  16. $atts['size'] = $tag->get_size_option( '40' ); 
  17. $atts['maxlength'] = $tag->get_maxlength_option(); 
  18. $atts['minlength'] = $tag->get_minlength_option(); 
  19.  
  20. if ( $atts['maxlength'] && $atts['minlength'] && $atts['maxlength'] < $atts['minlength'] ) { 
  21. unset( $atts['maxlength'], $atts['minlength'] ); 
  22.  
  23. $atts['class'] = $tag->get_class_option( $class ); 
  24. $atts['id'] = $tag->get_id_option(); 
  25. $atts['tabindex'] = $tag->get_option( 'tabindex', 'int', true ); 
  26. $atts['autocomplete'] = 'off'; 
  27. $atts['aria-required'] = 'true'; 
  28. $atts['aria-invalid'] = $validation_error ? 'true' : 'false'; 
  29.  
  30. $pipes = $tag->pipes; 
  31.  
  32. if ( $pipes instanceof WPCF7_Pipes && ! $pipes->zero() ) { 
  33. $pipe = $pipes->random_pipe(); 
  34. $question = $pipe->before; 
  35. $answer = $pipe->after; 
  36. } else { 
  37. // default quiz 
  38. $question = '1+1=?'; 
  39. $answer = '2'; 
  40.  
  41. $answer = wpcf7_canonicalize( $answer ); 
  42.  
  43. $atts['type'] = 'text'; 
  44. $atts['name'] = $tag->name; 
  45.  
  46. $atts = wpcf7_format_atts( $atts ); 
  47.  
  48. $html = sprintf( 
  49. '<span class="wpcf7-form-control-wrap %1$s"><label><span class="wpcf7-quiz-label">%2$s</span> <input %3$s /></label><input type="hidden" name="_wpcf7_quiz_answer_%4$s" value="%5$s" />%6$s</span>',  
  50. sanitize_html_class( $tag->name ),  
  51. esc_html( $question ), $atts, $tag->name,  
  52. wp_hash( $answer, 'wpcf7_quiz' ), $validation_error ); 
  53.  
  54. return $html;