PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / 3.5.2
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI v3.5.2
3.5.2 3.5.1 3.5.0 3.4.8 3.4.7 3.4.6 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5.1 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.10 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.6.1 1.6.7 1.7.0 1.7.0.1 1.7.0.2 1.7.0.3 1.7.1 1.7.2 1.7.2.1 1.7.2.2 1.7.3 1.7.4 1.7.5 1.7.5.1 1.7.5.2 1.7.6 1.7.7 1.7.7.1 1.7.7.2 1.7.8 1.7.9 1.8.0 1.8.0.1 1.8.1 1.8.2 1.8.2.1 1.8.2.2 1.8.2.3 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.0.1 1.9.1 1.9.2 1.9.3 1.9.4 1.9.4.1 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.0.1 2.0.1 2.0.2 2.0.3 2.0.3.1 2.0.4 2.0.4.1 2.0.5 2.0.6 2.0.7 2.0.8 2.0.8.1 2.0.9 3.0.0 3.0.0.1 3.0.1 3.0.2 3.0.3 3.0.3.1 3.0.4 3.0.4.1 3.0.4.2 3.0.5 3.0.5.1 3.0.5.2 3.0.6 3.0.6.1 3.0.7.1 3.0.8 3.0.8.1 3.0.9 3.0.9.1 3.0.9.2 3.0.9.3 3.0.9.4 3.0.9.5 3.1.0 3.1.1 3.1.2 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.3.0 3.4.0 3.4.1 3.4.2 3.4.2.1 3.4.3 3.4.4 3.4.5 trunk 1.0 1.0.1 1.0.2 1.0.3
everest-forms / includes / fields / class-evf-field-select.php
everest-forms / includes / fields Last commit date
class-evf-field-address.php 1 year ago class-evf-field-ai.php 1 year ago class-evf-field-captcha.php 3 weeks ago class-evf-field-checkbox.php 2 months ago class-evf-field-color.php 3 weeks ago class-evf-field-country.php 2 months ago class-evf-field-credit-card.php 3 weeks ago class-evf-field-date-time.php 3 weeks ago class-evf-field-divider.php 2 years ago class-evf-field-email.php 1 year ago class-evf-field-file-upload.php 1 year ago class-evf-field-first-name.php 1 year ago class-evf-field-hcaptcha.php 4 months ago class-evf-field-hidden.php 1 year ago class-evf-field-html.php 9 months ago class-evf-field-image-upload.php 1 year ago class-evf-field-last-name.php 1 year ago class-evf-field-likert.php 1 year ago class-evf-field-lookup.php 3 weeks ago class-evf-field-number.php 1 year ago class-evf-field-password.php 3 weeks ago class-evf-field-payment-authorize-net.php 3 weeks ago class-evf-field-payment-checkbox.php 3 weeks ago class-evf-field-payment-coupon.php 3 weeks ago class-evf-field-payment-gateway-selector.php 3 weeks ago class-evf-field-payment-quantity.php 3 weeks ago class-evf-field-payment-radio.php 3 weeks ago class-evf-field-payment-single.php 3 weeks ago class-evf-field-payment-square.php 1 year ago class-evf-field-payment-subscription-plan.php 3 weeks ago class-evf-field-payment-subtotal.php 3 weeks ago class-evf-field-payment-total.php 3 weeks ago class-evf-field-phone.php 1 year ago class-evf-field-privacy-policy.php 2 months ago class-evf-field-private-note.php 1 year ago class-evf-field-progress.php 3 weeks ago class-evf-field-radio.php 2 months ago class-evf-field-range-slider.php 3 weeks ago class-evf-field-rating.php 2 months ago class-evf-field-recaptcha.php 4 months ago class-evf-field-repeater.php 3 weeks ago class-evf-field-reset.php 3 weeks ago class-evf-field-scale-rating.php 1 year ago class-evf-field-select.php 1 year ago class-evf-field-signature.php 3 weeks ago class-evf-field-text.php 1 year ago class-evf-field-textarea.php 1 year ago class-evf-field-title.php 2 years ago class-evf-field-turnstile.php 4 months ago class-evf-field-url.php 1 year ago class-evf-field-wysiwyg.php 2 months ago class-evf-field-yes-no.php 1 year ago payment-amount-helpers.php 3 weeks ago
class-evf-field-select.php
439 lines
1 <?php
2 /**
3 * Select Dropdown field.
4 *
5 * @package EverestForms\Fields
6 * @since 1.0.0
7 */
8
9 defined( 'ABSPATH' ) || exit;
10
11 /**
12 * EVF_Field_Select class.
13 */
14 class EVF_Field_Select extends EVF_Form_Fields {
15
16 /**
17 * Constructor.
18 */
19 public function __construct() {
20 $this->name = esc_html__( 'Dropdown', 'everest-forms' );
21 $this->type = 'select';
22 $this->icon = 'evf-icon evf-icon-dropdown';
23 $this->order = 50;
24 $this->group = 'general';
25 $this->defaults = array(
26 1 => array(
27 'label' => esc_html__( 'Option 1', 'everest-forms' ),
28 'value' => '',
29 'default' => '',
30 ),
31 2 => array(
32 'label' => esc_html__( 'Option 2', 'everest-forms' ),
33 'value' => '',
34 'default' => '',
35 ),
36 3 => array(
37 'label' => esc_html__( 'Option 3', 'everest-forms' ),
38 'value' => '',
39 'default' => '',
40 ),
41 );
42 $this->settings = array(
43 'basic-options' => array(
44 'field_options' => array(
45 'label',
46 'choices',
47 'enhanced_select',
48 'description',
49 'required',
50 'required_field_message_setting',
51 'required_field_message',
52 ),
53 ),
54 'advanced-options' => array(
55 'field_options' => array(
56 'meta',
57 'size',
58 'show_values',
59 'placeholder',
60 'label_hide',
61 'css',
62 ),
63 ),
64 );
65
66 parent::__construct();
67 }
68
69 /**
70 * Hook in tabs.
71 */
72 public function init_hooks() {
73 add_action( 'everest_forms_shortcode_scripts', array( $this, 'load_assets' ) );
74 add_filter( 'everest_forms_field_properties_' . $this->type, array( $this, 'field_properties' ), 5, 3 );
75 }
76
77 /**
78 * Define additional field properties.
79 *
80 * @since 1.7.0
81 *
82 * @param array $properties Field properties.
83 * @param array $field Field settings.
84 * @param array $form_data Form data and settings.
85 *
86 * @return array of additional field properties.
87 */
88 public function field_properties( $properties, $field, $form_data ) {
89 // Define data.
90 $form_id = absint( $form_data['id'] );
91 $field_id = $field['id'];
92 $field = apply_filters( 'everest_forms_dropdown_options', $field );
93 $choices = $field['choices'];
94
95 // Remove primary input.
96 unset( $properties['inputs']['primary'] );
97
98 // Set input container (<select>) properties.
99 $properties['input_container'] = array(
100 'class' => array( 'input-text' ),
101 'data' => array(),
102 'id' => "evf-{$form_id}-field_{$field_id}",
103 'attr' => array(
104 'name' => "everest_forms[form_fields][{$field_id}]",
105 ),
106 );
107
108 // Set input properties.
109 foreach ( $choices as $key => $choice ) {
110 $depth = isset( $choice['depth'] ) ? absint( $choice['depth'] ) : 1;
111
112 $properties['inputs'][ $key ] = array(
113 'container' => array(
114 'attr' => array(),
115 'class' => array( "choice-{$key}", "depth-{$depth}" ),
116 'data' => array(),
117 'id' => '',
118 ),
119 'label' => array(
120 'attr' => array(
121 'for' => "evf-{$form_id}-field_{$field_id}_{$key}",
122 ),
123 'class' => array( 'everest-forms-field-label-inline' ),
124 'data' => array(),
125 'id' => '',
126 'text' => evf_string_translation( $form_id, $field_id, $choice['label'], '-choice-' . $key ),
127 ),
128 'attr' => array(
129 'name' => "everest_forms[form_fields][{$field_id}][]",
130 'value' => isset( $field['show_values'] ) ? $choice['value'] : $choice['label'],
131 ),
132 'class' => array(),
133 'data' => array(),
134 'id' => "evf-{$form_id}-field_{$field_id}_{$key}",
135 'required' => ! empty( $field['required'] ) ? 'required' : '',
136 'default' => isset( $choice['default'] ),
137 );
138 }
139
140 // Required class for validation.
141 if ( ! empty( $field['required'] ) ) {
142 $properties['input_container']['class'][] = 'evf-field-required';
143 }
144
145 return $properties;
146 }
147
148
149 /**
150 * Show values field option.
151 *
152 * @param array $field Field Data.
153 */
154 public function show_values( $field ) {
155 // Show Values toggle option. This option will only show if already used or if manually enabled by a filter.
156 if ( ! empty( $field['show_values'] ) || apply_filters( 'everest_forms_fields_show_options_setting', false ) ) {
157 $args = array(
158 'slug' => 'show_values',
159 'content' => $this->field_element(
160 'checkbox',
161 $field,
162 array(
163 'slug' => 'show_values',
164 'value' => isset( $field['show_values'] ) ? $field['show_values'] : '0',
165 'desc' => __( 'Show Values', 'everest-forms' ),
166 'tooltip' => __( 'Check this to manually set form field values.', 'everest-forms' ),
167 ),
168 false
169 ),
170 );
171 $this->field_element( 'row', $field, $args );
172 }
173 }
174
175 /**
176 * Register/queue frontend scripts.
177 *
178 * @param array $atts Shortcode attributes.
179 */
180 public static function load_assets( $atts ) {
181 $form_data = evf()->form->get( $atts['id'], array( 'content_only' => true ) );
182
183 if ( ! empty( $form_data['form_fields'] ) ) {
184 $is_enhanced_select = wp_list_filter(
185 $form_data['form_fields'],
186 array(
187 'type' => 'select',
188 'enhanced_select' => 1,
189 )
190 );
191
192 if ( ! empty( $is_enhanced_select ) ) {
193 wp_enqueue_style( 'evf_select2' );
194 wp_enqueue_script( 'selectWoo' );
195 }
196 }
197 }
198
199 /**
200 * Enable enhanced select field option.
201 *
202 * @param array $field Field Data.
203 */
204 public function enhanced_select( $field ) {
205 $plan = evf_get_license_plan();
206 $value = isset( $field['enhanced_select'] ) && false !== $plan ? $field['enhanced_select'] : '0';
207 $tooltip = esc_html__( 'Check this option to enable enhanced select. It enables you to search items in the dropdown field.', 'everest-forms' );
208
209 // Enable enhanced select toggle field.
210 $enhanced_select = $this->field_element(
211 'toggle',
212 $field,
213 array(
214 'slug' => 'enhanced_select',
215 'value' => $value,
216 'class' => ( false === $plan ) ? 'disabled' : '',
217 'desc' => esc_html__( 'Enable Enhanced Select', 'everest-forms' ),
218 'tooltip' => $tooltip,
219 ),
220 false
221 );
222 $this->field_element(
223 'row',
224 $field,
225 array(
226 'slug' => 'enhanced_select',
227 'content' => $enhanced_select,
228 'class' => ( false === $plan ) ? 'upgrade-modal' : '',
229 'data' => array(
230 'feature' => esc_html__( 'Enhanced select', 'everest-forms' ),
231 ),
232 )
233 );
234 }
235
236 /**
237 * Field preview inside the builder.
238 *
239 * @since 1.0.0
240 *
241 * @param array $field Field data and settings.
242 */
243 public function field_preview( $field ) {
244 $args = array();
245
246 if (
247 ! empty( $field['enhanced_select'] )
248 && ! empty( $field['multiple_choices'] ) && '1' === $field['multiple_choices']
249 ) {
250 $args['class'] = 'evf-enhanced-select';
251 }
252
253 // Label.
254 $this->field_preview_option( 'label', $field );
255
256 // Choices.
257 $this->field_preview_option( 'choices', $field, $args );
258
259 // Description.
260 $this->field_preview_option( 'description', $field );
261 }
262
263 /**
264 * Field display on the form front-end.
265 *
266 * @since 1.0.0
267 *
268 * @param array $field Field Data.
269 * @param array $field_atts Field attributes.
270 * @param array $form_data All Form Data.
271 */
272 public function field_display( $field, $field_atts, $form_data ) {
273 // Define data.
274 $container = $field['properties']['input_container'];
275 $choices = $field['properties']['inputs'];
276 $field = apply_filters( 'everest_forms_select_field_display', $field, $field_atts, $form_data );
277 $field_placeholder = ! empty( $field['placeholder'] ) ? evf_string_translation( $form_data['id'], $field['id'], $field['placeholder'], '-placeholder' ) : '';
278 $plan = evf_get_license_plan();
279 $has_default = false;
280 $is_multiple = false;
281 $select_all = isset( $field['select_all'] ) ? $field['select_all'] : '0';
282
283 if ( ! empty( $field['required'] ) ) {
284 $container['attr']['required'] = 'required';
285 }
286
287 // Enable enhanced select.
288 if ( false !== $plan && ! empty( $field['enhanced_select'] ) && '1' === $field['enhanced_select'] ) {
289 $container['class'][] = 'evf-enhanced-select';
290
291 if ( empty( $field_placeholder ) ) {
292 $first_choices = reset( $choices );
293 $field_placeholder = $first_choices['label']['text'];
294 }
295
296 // Set placeholder for select2.
297 $container['data']['placeholder'] = esc_attr( $field_placeholder );
298 }
299
300 // Enable multiple choices selection.
301 if ( false !== $plan && ! empty( $field['multiple_choices'] ) && '1' === $field['multiple_choices'] ) {
302 $is_multiple = true;
303 $container['attr']['multiple'] = 'multiple';
304
305 // Change a name attribute.
306 if ( ! empty( $container['attr']['name'] ) ) {
307 $container['attr']['name'] .= '[]';
308 }
309 }
310
311 // Check to see if any of the options have selected by default.
312 foreach ( $choices as $choice ) {
313 if ( ! empty( $choice['default'] ) ) {
314 $has_default = true;
315 break;
316 }
317 }
318
319 // Conditional logic.
320 if ( isset( $choices['primary'] ) ) {
321 $container['attr']['conditional_id'] = $choices['primary']['attr']['conditional_id'];
322
323 if ( isset( $choices['primary']['attr']['conditional_rules'] ) ) {
324 $container['attr']['conditional_rules'] = $choices['primary']['attr']['conditional_rules'];
325 }
326 }
327
328 // Select All checkbox.
329 if ( '1' === $select_all ) {
330 if ( isset( $container['attr']['multiple'] ) && 'multiple' === $container['attr']['multiple'] ) {
331 $container['attr']['select_all_unselect_all'] = 'true';
332 }
333 }
334
335 // Primary select field.
336 printf(
337 '<select %s >',
338 evf_html_attributes( $container['id'], $container['class'], $container['data'], $container['attr'] )
339 );
340
341 // Optional placeholder.
342 if ( ! empty( $field_placeholder ) ) {
343 printf( '<option value="" class="placeholder" disabled %s>%s</option>', selected( false, $has_default || $is_multiple, false ), esc_html( $field_placeholder ) );
344 }
345
346 // Build the select options.
347 foreach ( $choices as $choice ) {
348 if ( empty( $choice['container'] ) ) {
349 continue;
350 }
351
352 printf(
353 '<option value="%s" %s>%s</option>',
354 esc_attr( $choice['attr']['value'] ),
355 selected( true, ! empty( $choice['default'] ), false ),
356 esc_html( $choice['label']['text'] )
357 );
358 }
359
360 echo '</select>';
361 }
362
363 /**
364 * Edit form field display on the entry back-end.
365 *
366 * @since 1.7.0
367 *
368 * @param array $entry_field Entry field data.
369 * @param array $field Field data.
370 * @param array $form_data Form data and settings.
371 */
372 public function edit_form_field_display( $entry_field, $field, $form_data ) {
373 $value_choices = ! empty( $entry_field['value_raw'] ) ? $entry_field['value_raw'] : array();
374
375 $this->remove_field_choices_defaults( $field, $field['properties'] );
376
377 if ( is_array( $value_choices ) ) {
378 foreach ( $value_choices as $input => $single_value ) {
379 $field['properties'] = $this->get_single_field_property_value( $single_value, sanitize_key( $input ), $field['properties'], $field );
380 }
381 }
382
383 $this->field_display( $field, null, $form_data );
384 }
385
386 /**
387 * Formats and sanitizes field.
388 *
389 * @since 1.0.0
390 *
391 * @param int $field_id Field ID.
392 * @param mixed $field_submit Submitted field value.
393 * @param array $form_data Form data and settings.
394 * @param string $meta_key Field meta key.
395 */
396 public function format( $field_id, $field_submit, $form_data, $meta_key ) {
397 $field = $form_data['form_fields'][ $field_id ];
398 $name = make_clickable( $field['label'] );
399 $value = array();
400
401 // Convert field value into to array.
402 if ( ! is_array( $field_submit ) ) {
403 $field_submit = array( $field_submit );
404 }
405
406 $value_raw = evf_sanitize_array_combine( $field_submit );
407
408 $data = array(
409 'name' => $name,
410 'value' => '',
411 'value_raw' => $value_raw,
412 'id' => $field_id,
413 'type' => $this->type,
414 'meta_key' => $meta_key,
415 );
416
417 // Normal processing, dynamic population is off.
418 // If show_values is true, that means values posted are the raw values
419 // and not the labels. So we need to get the label values.
420 if ( ! empty( $field['show_values'] ) && '1' === $field['show_values'] ) {
421 foreach ( $field_submit as $item ) {
422 foreach ( $field['choices'] as $choice ) {
423 if ( $item === $choice['value'] ) {
424 $value[] = $choice['label'];
425 break;
426 }
427 }
428 }
429
430 $data['value'] = ! empty( $value ) ? evf_sanitize_array_combine( $value ) : '';
431 } else {
432 $data['value'] = $value_raw;
433 }
434
435 // Push field details to be saved.
436 evf()->task->form_fields[ $field_id ] = $data;
437 }
438 }
439