NF_Fields_Spam

Class NF_Fields_Spam.

Defined (1)

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

/includes/Fields/Spam.php  
  1. class NF_Fields_Spam extends NF_Abstracts_Input 
  2. protected $_name = 'spam'; 
  3.  
  4. protected $_type = 'spam'; 
  5.  
  6. protected $_section = 'misc'; 
  7.  
  8. protected $_icon = 'ban'; 
  9.  
  10. protected $_templates = 'textbox'; 
  11.  
  12. protected $_settings = array( 'spam_answer' ); 
  13.  
  14. public function __construct() 
  15. parent::__construct(); 
  16.  
  17. $this->_nicename = __( 'Anti-Spam', 'ninja-forms' ); 
  18.  
  19. // Rename Label setting to Question 
  20. $this->_settings[ 'label' ][ 'label' ] = __( 'Question', 'ninja-forms' ); 
  21. $this->_settings[ 'label_pos' ][ 'label' ] = __( 'Question Position', 'ninja-forms' ); 
  22.  
  23. // Manually set Field Key and stop tracking. 
  24. $this->_settings[ 'key' ][ 'value' ] = 'spam'; 
  25. $this->_settings[ 'manual_key' ][ 'value' ] = TRUE; 
  26.  
  27.  
  28. // Default Required setting to TRUE and hide setting. 
  29. $this->_settings[ 'required' ][ 'value' ] = 1; 
  30. $this->_settings[ 'required' ][ 'group' ] = ''; 
  31.  
  32. add_filter( 'nf_sub_hidden_field_types', array( $this, 'hide_field_type' ) ); 
  33.  
  34. /** 
  35. * Validate 
  36. * @param $field 
  37. * @param $data 
  38. * @return array $errors 
  39. */ 
  40. public function validate( $field, $data ) 
  41. $errors = parent::validate( $field, $data ); 
  42.  
  43. if( 
  44. ( isset( $field[ 'spam_answer' ] ) && isset( $field[ 'value' ] ) ) 
  45. && ( $field[ 'spam_answer' ] != $field[ 'value' ] ) 
  46. ) { 
  47. $errors[] = __( 'Incorrect Answer', 'ninja-forms' ); 
  48.  
  49. return $errors; 
  50.  
  51. public function get_parent_type() 
  52. return 'spam'; 
  53.  
  54. function hide_field_type( $field_types ) 
  55. $field_types[] = $this->_name; 
  56.  
  57. return $field_types; 
  58.