PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.3.4
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.3.4
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
← All changes | includes/fields/class-field-multidropdown.php +100 -116 1.6.281.3.4 View file →
@@ -1,116 +1,100 @@
1 -<?php
2 -
3 -/**
4 - * Text Field Class
5 - */
6 -class WeForms_Form_Field_MultiDropdown extends WeForms_Form_Field_Dropdown {
7 -
8 - public 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 int $form_id
19 - *
20 - * @return void
21 - */
22 - public function render( $field_settings, $form_id ) {
23 - $use_theme_css = isset( $form_settings['use_theme_css'] ) ? $form_settings['use_theme_css'] : 'wpuf-style';
24 - $selected = isset( $field_settings['selected'] ) ? $field_settings['selected'] : '';
25 - $selected = is_array( $selected ) ? $selected : [];
26 - $name = $field_settings['name'] . '[]'; ?>
27 - <li <?php $this->print_list_attributes( $field_settings ); ?>>
28 - <?php $this->print_label( $field_settings, $form_id ); ?>
29 -
30 - <?php do_action( 'weforms_multidropdown_field_after_label', $field_settings ); ?>
31 -
32 - <div class="wpuf-fields">
33 - <select
34 - multiple="multiple"
35 - class="multiselect <?php echo 'wpuf_'. esc_attr( $field_settings['name'] ) .'_'. esc_attr( $form_id ); ?>"
36 - id="<?php echo esc_attr($field_settings['name']) . '_' . esc_attr($form_id); ?>"
37 - name="<?php echo esc_attr($name); ?>"
38 - mulitple="multiple"
39 - data-required="<?php echo esc_attr($field_settings['required']) ?>"
40 - data-type="multiselect"
41 - data-style="<?php echo esc_attr( $use_theme_css ); ?>"
42 - >
43 -
44 - <?php if ( !empty( $field_settings['first'] ) ) { ?>
45 - <option value=""><?php echo esc_attr($field_settings['first']); ?></option>
46 - <?php } ?>
47 -
48 - <?php
49 - if ( $field_settings['options'] && count( $field_settings['options'] ) > 0 ) {
50 - foreach ($field_settings['options'] as $value => $option) {
51 - $current_select = selected( in_array( $value, $selected ), true, false );
52 - ?>
53 - <option value="<?php echo esc_attr( $value ); ?>"<?php echo esc_attr( $current_select ); ?>><?php echo esc_html( $option ); ?></option>
54 - <?php
55 - }
56 - } ?>
57 - </select>
58 - <?php $this->help_text( $field_settings ); ?>
59 - </div>
60 -
61 - </li>
62 - <?php
63 - }
64 -
65 - /**
66 - * Get the field props
67 - *
68 - * @return array
69 - */
70 - public function get_field_props() {
71 - $defaults = $this->default_attributes();
72 - $props = [
73 - 'selected' => [],
74 - 'options' => [ 'Option' => __( 'Option', 'weforms' ) ],
75 - 'first' => __( '— Select —', 'weforms' ),
76 - ];
77 -
78 - $props = apply_filters( 'weforms_multidropdown_field_props', $props );
79 -
80 - return array_merge( $defaults, $props );
81 - }
82 -
83 - /**
84 - * Prepare entry
85 - *
86 - * @param $field
87 - *
88 - * @return mixed
89 - */
90 - public function prepare_entry( $field, $args = [] ) {
91 - if( empty( $_POST[ '_wpnonce' ] ) ) {
92 - wp_send_json_error( __( 'Unauthorized operation', 'weforms' ) );
93 - }
94 -
95 - if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ), 'wpuf_form_add' ) ) {
96 - wp_send_json_error( __( 'Unauthorized operation', 'weforms' ) );
97 - }
98 -
99 - $args = ! empty( $args ) ? $args : weforms_clean( $_POST );
100 - $entry_value = ( is_array( $args[$field['name']] ) && $args[$field['name']] ) ? $args[$field['name']] : array();
101 -
102 - if ( $entry_value ) {
103 - $new_val = [];
104 -
105 - foreach ( $entry_value as $option_key ) {
106 - $new_val[] = isset( $field['options'][$option_key] ) ? $field['options'][$option_key] : $option_key;
107 - }
108 -
109 - $entry_value = implode( WeForms::$field_separator, $new_val );
110 - } else {
111 - $entry_value = '';
112 - }
113 -
114 - return $entry_value;
115 - }
116 -}
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 + <?php do_action( 'weforms_multidropdown_field_after_label', $field_settings ); ?>
31 +
32 + <div class="wpuf-fields">
33 + <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">
34 +
35 + <?php if ( !empty( $field_settings['first'] ) ) { ?>
36 + <option value=""><?php echo $field_settings['first']; ?></option>
37 + <?php } ?>
38 +
39 + <?php
40 + if ( $field_settings['options'] && count( $field_settings['options'] ) > 0 ) {
41 + foreach ($field_settings['options'] as $value => $option) {
42 + $current_select = selected( in_array( $value, $selected ), true, false );
43 + ?>
44 + <option value="<?php echo esc_attr( $value ); ?>"<?php echo $current_select; ?>><?php echo $option; ?></option>
45 + <?php
46 + }
47 + }
48 + ?>
49 + </select>
50 + <?php $this->help_text( $field_settings ); ?>
51 + </div>
52 +
53 + </li>
54 + <?php
55 + }
56 +
57 + /**
58 + * Get the field props
59 + *
60 + * @return array
61 + */
62 + public function get_field_props() {
63 + $defaults = $this->default_attributes();
64 + $props = array(
65 + 'selected' => array(),
66 + 'options' => array( 'Option' => __( 'Option', 'weforms' ) ),
67 + 'first' => __( '— Select —', 'weforms' ),
68 + );
69 +
70 + $props = apply_filters( 'weforms_multidropdown_field_props', $props );
71 +
72 + return array_merge( $defaults, $props );
73 + }
74 +
75 + /**
76 + * Prepare entry
77 + *
78 + * @param $field
79 + *
80 + * @return mixed
81 + */
82 + public function prepare_entry( $field ) {
83 +
84 + $entry_value = ( is_array( $_POST[$field['name']] ) && $_POST[$field['name']] ) ? $_POST[$field['name']] : array();
85 +
86 + if ( $entry_value ) {
87 + $new_val = array();
88 +
89 + foreach ($entry_value as $option_key) {
90 + $new_val[] = isset( $field['options'][$option_key] ) ? $field['options'][$option_key] : '';
91 + }
92 +
93 + $entry_value = implode( WeForms::$field_separator, $new_val );
94 + } else {
95 + $entry_value = '';
96 + }
97 +
98 + return $entry_value;
99 + }
100 +}