1: <?php
2:
3: 4: 5:
6: class Quform_Element_Email 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: public function getValueHtml()
25: {
26: $value = '';
27:
28: if ( ! $this->isEmpty()) {
29: $value = sprintf('<a href="mailto:%1$s">%1$s</a>', Quform::escape($this->getValue()));
30: }
31:
32: $value = apply_filters('quform_get_value_html_' . $this->getIdentifier(), $value, $this, $this->getForm());
33:
34: return $value;
35: }
36:
37: 38: 39: 40: 41: 42:
43: protected function getFieldAttributes(array $context = array())
44: {
45: $attributes = array(
46: 'type' => 'email',
47: 'id' => $this->getUniqueId(),
48: 'name' => $this->getFullyQualifiedName(),
49: 'class' => Quform::sanitizeClass($this->getFieldClasses($context))
50: );
51:
52: if ( ! $this->isEmpty()) {
53: $attributes['value'] = $this->getValue();
54: }
55:
56: $placeholder = $this->form->replaceVariablesPreProcess($this->config('placeholder'));
57: if (Quform::isNonEmptyString($placeholder)) {
58: $attributes['placeholder'] = $placeholder;
59: }
60:
61: if (Quform::isNonEmptyString($this->config('autocomplete'))) {
62: $attributes['autocomplete'] = $this->config('autocomplete');
63: }
64:
65: if (Quform::isNonEmptyString($this->config('maxLength'))) {
66: $attributes['maxlength'] = $this->config('maxLength');
67: }
68:
69: if ($this->config('readOnly')) {
70: $attributes['readonly'] = true;
71: }
72:
73: $attributes = apply_filters('quform_field_attributes', $attributes, $this, $this->form, $context);
74: $attributes = apply_filters('quform_field_attributes_' . $this->getIdentifier(), $attributes, $this, $this->form, $context);
75:
76: return $attributes;
77: }
78:
79: 80: 81: 82: 83: 84:
85: protected function getFieldClasses(array $context = array())
86: {
87: $classes = array(
88: 'quform-field',
89: 'quform-field-email',
90: sprintf('quform-field-%s', $this->getIdentifier())
91: );
92:
93: if ($this->form->config('tooltipsEnabled') && Quform::isNonEmptyString($this->config('tooltip')) && Quform::get($context, 'tooltipType') == 'field') {
94: $classes[] = sprintf('quform-tooltip-%s', Quform::get($context, 'tooltipEvent'));
95: }
96:
97: if (Quform::isNonEmptyString($this->config('customClass'))) {
98: $classes[] = $this->config('customClass');
99: }
100:
101: $classes = apply_filters('quform_field_classes', $classes, $this, $this->form, $context);
102: $classes = apply_filters('quform_field_classes_' . $this->getIdentifier(), $classes, $this, $this->form, $context);
103:
104: return $classes;
105: }
106:
107: 108: 109: 110: 111: 112:
113: protected function getFieldHtml(array $context = array())
114: {
115: return Quform::getHtmlTag('input', $this->getFieldAttributes($context));
116: }
117:
118: 119: 120: 121: 122:
123: public function getEditFieldHtml()
124: {
125: return $this->getFieldHtml();
126: }
127:
128: 129: 130: 131: 132: 133:
134: protected function renderCss(array $context = array())
135: {
136: $css = parent::renderCss($context);
137:
138: if ($context['fieldWidth'] == 'custom' && Quform::isNonEmptyString($context['fieldWidthCustom'])) {
139: $css .= sprintf('.quform-input-email.quform-input-%s { width: %s; }', $this->getIdentifier(), Quform::addCssUnit($context['fieldWidthCustom']));
140: $css .= sprintf('.quform-inner-%s > .quform-error > .quform-error-inner { float: left; min-width: %s; }', $this->getIdentifier(), Quform::addCssUnit($context['fieldWidthCustom']));
141: }
142:
143: return $css;
144: }
145:
146: 147: 148: 149: 150: 151:
152: public static function getDefaultConfig($key = null)
153: {
154: $config = apply_filters('quform_default_config_email', array(
155:
156: 'label' => __('Email address', 'quform'),
157: 'description' => '',
158: 'descriptionAbove' => '',
159: 'required' => true,
160:
161:
162: 'labelIcon' => '',
163: 'fieldIconLeft' => '',
164: 'fieldIconRight' => '',
165: 'fieldSize' => 'inherit',
166: 'fieldWidth' => 'inherit',
167: 'fieldWidthCustom' => '',
168: 'customClass' => '',
169: 'customElementClass' => '',
170: 'styles' => array(),
171:
172:
173: 'placeholder' => '',
174: 'subLabel' => '',
175: 'subLabelAbove' => '',
176: 'adminLabel' => '',
177: 'tooltip' => '',
178: 'tooltipType' => 'inherit',
179: 'tooltipEvent' => 'inherit',
180: 'labelPosition' => 'inherit',
181: 'labelWidth' => '',
182:
183:
184: 'logicEnabled' => false,
185: 'logicAction' => true,
186: 'logicMatch' => 'all',
187: 'logicRules' => array(),
188:
189:
190: 'defaultValue' => '',
191: 'dynamicDefaultValue' => false,
192: 'dynamicKey' => '',
193: 'autocomplete' => '',
194: 'maxLength' => '',
195: 'readOnly' => false,
196: 'showInEmail' => true,
197: 'saveToDatabase' => true,
198:
199:
200: 'visibility' => '',
201: 'filters' => array(array('type' => 'trim')),
202: 'validators' => array(),
203:
204:
205: 'messageRequired' => '',
206: 'messageEmailAddressInvalidFormat' => '',
207: 'messageLengthTooLong' => ''
208: ));
209:
210: $config['type'] = 'email';
211:
212: if (Quform::isNonEmptyString($key)) {
213: return Quform::get($config, $key);
214: }
215:
216: return $config;
217: }
218: }
219: