1: <?php
2:
3: 4: 5:
6: class Quform_Element_Hidden extends Quform_Element_Field implements Quform_Element_Editable
7: {
8: 9: 10: 11: 12: 13:
14: public function setDefaultValue($value, $replacePlaceholders = true)
15: {
16: $this->defaultValue = $replacePlaceholders ? $this->getForm()->replaceVariablesPreProcess($value) : $value;
17: }
18:
19: 20: 21: 22: 23: 24:
25: protected function getFieldAttributes(array $context = array())
26: {
27: $attributes = array(
28: 'type' => 'hidden',
29: 'name' => $this->getFullyQualifiedName(),
30: 'class' => Quform::sanitizeClass($this->getFieldClasses($context)),
31: 'data-default' => $this->getValue()
32: );
33:
34: if ( ! $this->isEmpty()) {
35: $attributes['value'] = $this->getValue();
36: }
37:
38: $attributes = apply_filters('quform_field_attributes', $attributes, $this, $this->form, $context);
39: $attributes = apply_filters('quform_field_attributes_' . $this->getIdentifier(), $attributes, $this, $this->form, $context);
40:
41: return $attributes;
42: }
43:
44: 45: 46: 47: 48: 49:
50: protected function getFieldClasses(array $context = array())
51: {
52: $classes = array(
53: 'quform-field',
54: 'quform-field-hidden',
55: sprintf('quform-field-%s', $this->getIdentifier())
56: );
57:
58: if (Quform::isNonEmptyString($this->config('customClass'))) {
59: $classes[] = $this->config('customClass');
60: }
61:
62: $classes = apply_filters('quform_field_classes', $classes, $this, $this->form, $context);
63: $classes = apply_filters('quform_field_classes_' . $this->getIdentifier(), $classes, $this, $this->form, $context);
64:
65: return $classes;
66: }
67:
68: 69: 70: 71: 72: 73:
74: protected function getFieldHtml(array $context = array())
75: {
76: return Quform::getHtmlTag('input', $this->getFieldAttributes($context));
77: }
78:
79: 80: 81: 82: 83: 84:
85: public function render(array $context = array())
86: {
87: return $this->getFieldHtml();
88: }
89:
90: 91: 92: 93: 94:
95: public function getEditFieldHtml()
96: {
97: $attributes = $this->getFieldAttributes();
98: $attributes['type'] = 'text';
99:
100: return Quform::getHtmlTag('input', $attributes);
101: }
102:
103: 104: 105: 106: 107: 108:
109: public static function getDefaultConfig($key = null)
110: {
111: $config = apply_filters('quform_default_config_hidden', array(
112:
113: 'label' => __('Hidden', 'quform'),
114:
115:
116: 'customClass' => '',
117:
118:
119: 'defaultValue' => '',
120: 'dynamicDefaultValue' => false,
121: 'dynamicKey' => '',
122: 'showInEmail' => true,
123: 'saveToDatabase' => true,
124:
125:
126: 'visibility' => ''
127: ));
128:
129: $config['type'] = 'hidden';
130:
131: if (Quform::isNonEmptyString($key)) {
132: return Quform::get($config, $key);
133: }
134:
135: return $config;
136: }
137: }
138: