1: <?php
2:
3: 4: 5:
6: class Quform_Element_Honeypot extends Quform_Element_Field
7: {
8: 9: 10: 11: 12: 13:
14: public function render(array $context = array())
15: {
16: $output = '<div class="quform-element-tree">';
17:
18: $output .= sprintf(
19: '<label for="%s">%s</label>',
20: esc_attr($this->getUniqueId()),
21: esc_html__('This field should be left blank', 'quform')
22: );
23:
24: $output .= $this->getFieldHtml($context);
25:
26: $output .= '</div>';
27:
28: return $output;
29: }
30:
31: 32: 33: 34: 35: 36:
37: protected function getFieldAttributes(array $context = array())
38: {
39: $attributes = array(
40: 'type' => 'text',
41: 'id' => $this->getUniqueId(),
42: 'name' => $this->getFullyQualifiedName(),
43: 'class' => Quform::sanitizeClass($this->getFieldClasses($context)),
44: 'tabindex' => '-1',
45: 'autocomplete' => 'off'
46: );
47:
48: $attributes = apply_filters('quform_field_attributes', $attributes, $this, $this->form, $context);
49: $attributes = apply_filters('quform_field_attributes_' . $this->getIdentifier(), $attributes, $this, $this->form, $context);
50:
51: return $attributes;
52: }
53:
54: 55: 56: 57: 58: 59:
60: protected function getFieldClasses(array $context = array())
61: {
62: $classes = array(
63: 'quform-field',
64: 'quform-field-tree',
65: sprintf('quform-field-%s', $this->getIdentifier())
66: );
67:
68: $classes = apply_filters('quform_field_classes', $classes, $this, $this->form, $context);
69: $classes = apply_filters('quform_field_classes_' . $this->getIdentifier(), $classes, $this, $this->form, $context);
70:
71: return $classes;
72: }
73:
74: 75: 76: 77: 78: 79:
80: protected function getFieldHtml(array $context = array())
81: {
82: return Quform::getHtmlTag('input', $this->getFieldAttributes($context));
83: }
84:
85: 86: 87: 88: 89: 90:
91: public static function getDefaultConfig($key = null)
92: {
93: $config = apply_filters('quform_default_config_honeypot', array(
94: 'showInEmail' => false,
95: 'saveToDatabase' => false
96: ));
97:
98: $config['type'] = 'honeypot';
99:
100: if (Quform::isNonEmptyString($key)) {
101: return Quform::get($config, $key);
102: }
103:
104: return $config;
105: }
106: }
107: