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: $context = $this->prepareContext($context);
17:
18: $labels = apply_filters(
19: 'quform_honeypot_labels',
20: array(
21: 'Email',
22: 'Email Address',
23: 'Website URL',
24: 'Your Website',
25: 'Contact Email',
26: 'Business Email',
27: 'Phone Number',
28: 'Company Name'
29: )
30: );
31:
32: $inlineStyle = 'clip: rect(1px, 1px, 1px, 1px); clip-path: inset(50%); position: absolute !important; height: 1px; width: 1px; overflow: hidden;';
33:
34: $output = sprintf('<div class="quform-element quform-element-textarea quform-element-%s quform-sr-only quform-cf" style="%s">',
35: esc_attr($this->getIdentifier()),
36: esc_attr($inlineStyle)
37: );
38:
39: $output .= '<div class="quform-spacer">';
40:
41: $output .= sprintf('<div class="quform-label quform-label-%s">', esc_attr($this->getIdentifier()));
42: $output .= sprintf('<label class="quform-label-text" for="%s">%s%s</label>',
43: esc_attr($this->getUniqueId()),
44: esc_html($labels[array_rand($labels)]),
45: Quform::isNonEmptyString($requiredText = $this->form->config('requiredText')) ? '<span class="quform-required">' . esc_html($requiredText) . '</span>' : ''
46: );
47: $output .= '</div>';
48:
49: $output .= sprintf('<div class="quform-inner quform-inner-%s">', esc_attr($this->getIdentifier()));
50:
51: $output .= $this->getFieldHtml($context);
52:
53: $output .= '</div></div></div>';
54:
55: return $output;
56: }
57:
58: 59: 60: 61: 62: 63:
64: protected function getFieldAttributes(array $context = array())
65: {
66: $attributes = array(
67: 'id' => $this->getUniqueId(),
68: 'name' => $this->getFullyQualifiedName(),
69: 'class' => Quform::sanitizeClass($this->getFieldClasses($context)),
70: 'tabindex' => '-1',
71: 'autocomplete' => 'new-password'
72: );
73:
74: $attributes = apply_filters('quform_field_attributes', $attributes, $this, $this->form, $context);
75: $attributes = apply_filters('quform_field_attributes_' . $this->getIdentifier(), $attributes, $this, $this->form, $context);
76:
77: return $attributes;
78: }
79:
80: 81: 82: 83: 84: 85:
86: protected function getFieldClasses(array $context = array())
87: {
88: $classes = array(
89: 'quform-field',
90: 'quform-field-textarea',
91: sprintf('quform-field-%s', $this->getIdentifier())
92: );
93:
94: $classes = apply_filters('quform_field_classes', $classes, $this, $this->form, $context);
95: $classes = apply_filters('quform_field_classes_' . $this->getIdentifier(), $classes, $this, $this->form, $context);
96:
97: return $classes;
98: }
99:
100: 101: 102: 103: 104: 105:
106: protected function getFieldHtml(array $context = array())
107: {
108: return Quform::getHtmlTag('textarea', $this->getFieldAttributes($context));
109: }
110:
111: 112: 113: 114: 115: 116:
117: public static function getDefaultConfig($key = null)
118: {
119: $config = apply_filters('quform_default_config_honeypot', array(
120: 'showInEmail' => false,
121: 'saveToDatabase' => false
122: ));
123:
124: $config['type'] = 'honeypot';
125:
126: if (Quform::isNonEmptyString($key)) {
127: return Quform::get($config, $key);
128: }
129:
130: return $config;
131: }
132: }
133: