PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.2.8
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.2.8
1.6.7 1.6.8 1.6.9 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.18 1.6.19 1.6.2 1.6.20 1.6.21 1.6.22 1.6.23 1.6.24 1.6.25 1.6.26 1.6.27 1.6.28 1.6.3 1.6.4 1.6.5 1.6.6 All 74 releases
weforms / includes / fields / class-field-multidropdown.php

class-field-multidropdown.php in weForms – Easy Drag & Drop Contact Form Builder For WordPress 1.2.8, at includes/fields/class-field-multidropdown.php

96 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Text Field Class
5 */
6 class WeForms_Form_Field_MultiDropdown extends WeForms_Form_Field_Dropdown {
7
8 function __construct() {
9 $this->name = __( 'Multi Select', 'weforms' );
10 $this->input_type = 'multiple_select';
11 $this->icon = 'list-ul';
12 }
13
14 /**
15 * Render the text field
16 *
17 * @param array $field_settings
18 * @param integer $form_id
19 *
20 * @return void
21 */
22 public function render( $field_settings, $form_id ) {
23 $selected = isset( $field_settings['selected'] ) ? $field_settings['selected'] : '';
24 $selected = is_array( $selected ) ? $selected : array();
25 $name = $field_settings['name'] . '[]';
26 ?>
27 <li <?php $this->print_list_attributes( $field_settings ); ?>>
28 <?php $this->print_label( $field_settings, $form_id ); ?>
29
30 <div class="wpuf-fields">
31 <select multiple="multiple" class="multiselect <?php echo 'wpuf_'. $field_settings['name'] .'_'. $form_id; ?>" id="<?php echo $field_settings['name'] . '_' . $form_id; ?>" name="<?php echo $name; ?>" mulitple="multiple" data-required="<?php echo $field_settings['required'] ?>" data-type="multiselect">
32
33 <?php if ( !empty( $field_settings['first'] ) ) { ?>
34 <option value=""><?php echo $field_settings['first']; ?></option>
35 <?php } ?>
36
37 <?php
38 if ( $field_settings['options'] && count( $field_settings['options'] ) > 0 ) {
39 foreach ($field_settings['options'] as $value => $option) {
40 $current_select = selected( in_array( $value, $selected ), true, false );
41 ?>
42 <option value="<?php echo esc_attr( $value ); ?>"<?php echo $current_select; ?>><?php echo $option; ?></option>
43 <?php
44 }
45 }
46 ?>
47 </select>
48 <?php $this->help_text( $field_settings ); ?>
49 </div>
50
51 </li>
52 <?php
53 }
54
55 /**
56 * Get the field props
57 *
58 * @return array
59 */
60 public function get_field_props() {
61 $defaults = $this->default_attributes();
62 $props = array(
63 'selected' => array(),
64 'options' => array( 'Option' => __( 'Option', 'weforms' ) ),
65 'first' => __( '— Select —', 'weforms' ),
66 );
67
68 return array_merge( $defaults, $props );
69 }
70
71 /**
72 * Prepare entry
73 *
74 * @param $field
75 *
76 * @return mixed
77 */
78 public function prepare_entry( $field ) {
79
80 $entry_value = ( is_array( $_POST[$field['name']] ) && $_POST[$field['name']] ) ? $_POST[$field['name']] : array();
81
82 if ( $entry_value ) {
83 $new_val = array();
84
85 foreach ($entry_value as $option_key) {
86 $new_val[] = isset( $field['options'][$option_key] ) ? $field['options'][$option_key] : '';
87 }
88
89 $entry_value = implode( WeForms::$field_separator, $new_val );
90 } else {
91 $entry_value = '';
92 }
93
94 return $entry_value;
95 }
96 }