PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.4.0
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.4.0
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-checkbox.php

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

129 lines 4.1 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_Checkbox extends WeForms_Field_Contract {
7
8 function __construct() {
9 $this->name = __( 'Checkbox', 'weforms' );
10 $this->input_type = 'checkbox_field';
11 $this->icon = 'check-square-o';
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 = !empty( $field_settings['selected'] ) ? $field_settings['selected'] : array();
24 ?>
25 <li <?php $this->print_list_attributes( $field_settings ); ?>>
26 <?php $this->print_label( $field_settings, $form_id ); ?>
27
28 <?php do_action( 'weforms_checkbox_field_after_label', $field_settings ); ?>
29
30 <div class="wpuf-fields" data-required="<?php echo $field_settings['required'] ?>" data-type="radio">
31
32 <?php
33 if ( $field_settings['options'] && count( $field_settings['options'] ) > 0 ) {
34
35 foreach ($field_settings['options'] as $value => $option) {
36
37 ?>
38 <label <?php echo $field_settings['inline'] == 'yes' ? 'class="wpuf-checkbox-inline"' : 'class="wpuf-checkbox-block"'; ?>>
39 <input type="checkbox" class="<?php echo 'wpuf_' . $field_settings['name']. '_'. $form_id; ?>" name="<?php echo $field_settings['name']; ?>[]" value="<?php echo esc_attr( $value ); ?>"<?php echo in_array( $value, $selected ) ? ' checked="checked"' : ''; ?> />
40 <?php echo $option; ?>
41 </label>
42 <?php
43 }
44 }
45 ?>
46
47 <?php $this->help_text( $field_settings ); ?>
48
49 </div>
50 </li>
51 <?php
52 }
53
54 /**
55 * Get field options setting
56 *
57 * @return array
58 */
59 public function get_options_settings() {
60 $default_options = $this->get_default_option_settings( true, array( 'width' ) );
61 $dropdown_options = array(
62 $this->get_default_option_dropdown_settings( true ),
63
64 array(
65 'name' => 'inline',
66 'title' => __( 'Show in inline list', 'weforms' ),
67 'type' => 'radio',
68 'options' => array(
69 'yes' => __( 'Yes', 'weforms' ),
70 'no' => __( 'No', 'weforms' ),
71 ),
72 'default' => 'no',
73 'inline' => true,
74 'section' => 'advanced',
75 'priority' => 23,
76 'help_text' => __( 'Show this option in an inline list', 'weforms' ),
77 ),
78
79 );
80
81 $dropdown_options = apply_filters( 'weforms_checkbox_field_option_settings', $dropdown_options );
82
83 return array_merge( $default_options, $dropdown_options );
84 }
85
86 /**
87 * Get the field props
88 *
89 * @return array
90 */
91 public function get_field_props() {
92 $defaults = $this->default_attributes();
93 $props = array(
94 'selected' => array(),
95 'inline' => 'no',
96 'options' => array( 'Option' => __( 'Option', 'weforms' ) ),
97 );
98
99 $props = apply_filters( 'weforms_checkbox_field_props', $props );
100
101 return array_merge( $defaults, $props );
102 }
103
104 /**
105 * Prepare entry
106 *
107 * @param $field
108 *
109 * @return mixed
110 */
111 public function prepare_entry( $field ) {
112
113 $entry_value = ( is_array( $_POST[$field['name']] ) && $_POST[$field['name']] ) ? $_POST[$field['name']] : array();
114
115 if ( $entry_value ) {
116 $new_val = array();
117
118 foreach ($entry_value as $option_key) {
119 $new_val[] = isset( $field['options'][$option_key] ) ? $field['options'][$option_key] : '';
120 }
121
122 $entry_value = implode( WeForms::$field_separator, $new_val );
123 } else {
124 $entry_value = '';
125 }
126
127 return $entry_value;
128 }
129 }