PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.2.2
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.2.2
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-dropdown.php +110 -124 1.6.211.2.2 View file →
@@ -1,124 +1,110 @@
1 -<?php
2 -
3 -/**
4 - * Text Field Class
5 - */
6 -class WeForms_Form_Field_Dropdown extends WeForms_Field_Contract {
7 -
8 - public function __construct() {
9 - $this->name = __( 'Dropdown', 'weforms' );
10 - $this->input_type = 'dropdown_field';
11 - $this->icon = 'caret-square-o-down';
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 - $name = $field_settings['name']; ?>
26 - <li <?php $this->print_list_attributes( $field_settings ); ?>>
27 - <?php $this->print_label( $field_settings, $form_id ); ?>
28 -
29 - <?php do_action( 'weforms_dropdown_field_after_label', $field_settings ); ?>
30 -
31 - <div class="wpuf-fields">
32 - <select
33 - class="<?php echo 'wpuf_'. esc_attr( $field_settings['name'] ) .'_'. esc_attr( $form_id ); ?>"
34 - id="<?php echo esc_attr( $field_settings['name'] ) . '_' . esc_attr( $form_id ); ?>"
35 - name="<?php echo esc_attr( $name ); ?>"
36 - data-required="<?php echo esc_attr( $field_settings['required'] ) ?>"
37 - data-type="select"
38 - data-style="<?php echo esc_attr( $use_theme_css ); ?>"
39 - >
40 - <?php if ( !empty( $field_settings['first'] ) ) { ?>
41 - <option value=""><?php echo esc_attr( $field_settings['first'] ); ?></option>
42 - <?php } ?>
43 - <?php
44 - if ( $field_settings['options'] && count( $field_settings['options'] ) > 0 ) {
45 - foreach ($field_settings['options'] as $value => $option) {
46 - $current_select = selected( $selected, $value, false );
47 - ?>
48 - <option value="<?php echo esc_attr( $value ); ?>"<?php echo esc_attr( $current_select ); ?>><?php echo
49 - esc_attr( $option ); ?></option>
50 - <?php
51 - }
52 - } ?>
53 - </select>
54 - <?php $this->help_text( $field_settings ); ?>
55 - </div>
56 -
57 - </li>
58 - <?php
59 - }
60 -
61 - /**
62 - * Get field options setting
63 - *
64 - * @return array
65 - */
66 - public function get_options_settings() {
67 - $default_options = $this->get_default_option_settings();
68 - $dropdown_options = [
69 - $this->get_default_option_dropdown_settings(),
70 - [
71 - 'name' => 'first',
72 - 'title' => __( 'Select Text', 'weforms' ),
73 - 'type' => 'text',
74 - 'section' => 'basic',
75 - 'priority' => 13,
76 - 'help_text' => __( "First element of the select dropdown. Leave this empty if you don't want to show this field", 'weforms' ),
77 - ],
78 - ];
79 -
80 - $dropdown_options = apply_filters( 'weforms_dropdown_field_option_settings', $dropdown_options );
81 -
82 - return array_merge( $default_options, $dropdown_options );
83 - }
84 -
85 - /**
86 - * Get the field props
87 - *
88 - * @return array
89 - */
90 - public function get_field_props() {
91 - $defaults = $this->default_attributes();
92 - $props = [
93 - 'selected' => '',
94 - 'options' => [ 'Option' => __( 'Option', 'weforms' ) ],
95 - 'first' => __( '— Select —', 'weforms' ),
96 - ];
97 -
98 - $props = apply_filters( 'weforms_dropdown_field_props', $props );
99 -
100 - return array_merge( $defaults, $props );
101 - }
102 -
103 - /**
104 - * Prepare entry
105 - *
106 - * @param $field
107 - *
108 - * @return mixed
109 - */
110 - public function prepare_entry( $field, $args = [] ) {
111 - if( empty( $_POST['_wpnonce'])) {
112 - wp_send_json_error( __( 'Unauthorized operation', 'weforms' ) );
113 - }
114 -
115 - if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ), 'wpuf_form_add' ) ) {
116 - wp_send_json_error( __( 'Unauthorized operation', 'weforms' ) );
117 - }
118 -
119 - $args = ! empty( $args ) ? $args : weforms_clean( $_POST );
120 - $val = $args[$field['name']];
121 -
122 - return isset( $field['options'][$val] ) ? $field['options'][$val] : $val;
123 - }
124 -}
1 +<?php
2 +
3 +/**
4 + * Text Field Class
5 + */
6 +class WeForms_Form_Field_Dropdown extends WeForms_Field_Contract {
7 +
8 + function __construct() {
9 + $this->name = __( 'Dropdown', 'weforms' );
10 + $this->input_type = 'dropdown_field';
11 + $this->icon = 'caret-square-o-down';
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 + $name = $field_settings['name'];
25 + ?>
26 + <li <?php $this->print_list_attributes( $field_settings ); ?>>
27 + <?php $this->print_label( $field_settings, $form_id ); ?>
28 +
29 + <div class="wpuf-fields">
30 + <select
31 + class="<?php echo 'wpuf_'. $field_settings['name'] .'_'. $form_id; ?>"
32 + id="<?php echo $field_settings['name'] . '_' . $form_id; ?>"
33 + name="<?php echo $name; ?>"
34 + data-required="<?php echo $field_settings['required'] ?>"
35 + data-type="select">
36 +
37 + <?php if ( !empty( $field_settings['first'] ) ) { ?>
38 + <option value=""><?php echo $field_settings['first']; ?></option>
39 + <?php } ?>
40 +
41 + <?php
42 + if ( $field_settings['options'] && count( $field_settings['options'] ) > 0 ) {
43 + foreach ($field_settings['options'] as $value => $option) {
44 + $current_select = selected( $selected, $value, false );
45 + ?>
46 + <option value="<?php echo esc_attr( $value ); ?>"<?php echo $current_select; ?>><?php echo $option; ?></option>
47 + <?php
48 + }
49 + }
50 + ?>
51 + </select>
52 + <?php $this->help_text( $field_settings ); ?>
53 + </div>
54 +
55 + </li>
56 + <?php
57 + }
58 +
59 + /**
60 + * Get field options setting
61 + *
62 + * @return array
63 + */
64 + public function get_options_settings() {
65 + $default_options = $this->get_default_option_settings();
66 + $dropdown_options = array(
67 + $this->get_default_option_dropdown_settings(),
68 +
69 + array(
70 + 'name' => 'first',
71 + 'title' => __( 'Select Text', 'wpuf' ),
72 + 'type' => 'text',
73 + 'section' => 'basic',
74 + 'priority' => 13,
75 + 'help_text' => __( "First element of the select dropdown. Leave this empty if you don't want to show this field", 'wpuf' ),
76 + ),
77 + );
78 +
79 + return array_merge( $default_options, $dropdown_options );
80 + }
81 +
82 + /**
83 + * Get the field props
84 + *
85 + * @return array
86 + */
87 + public function get_field_props() {
88 + $defaults = $this->default_attributes();
89 + $props = array(
90 + 'selected' => '',
91 + 'options' => array( 'Option' => __( 'Option', 'wpuf' ) ),
92 + 'first' => __( '— Select —', 'wpuf' ),
93 + );
94 +
95 + return array_merge( $defaults, $props );
96 + }
97 +
98 + /**
99 + * Prepare entry
100 + *
101 + * @param $field
102 + *
103 + * @return mixed
104 + */
105 + public function prepare_entry( $field ) {
106 +
107 + $val = $_POST[$field['name']];
108 + return isset( $field['options'][$val] ) ? $field['options'][$val] : '';
109 + }
110 +}