PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.1.1
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.1.1
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 / class-field-manager.php

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

166 lines 5.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Form field manager class
5 *
6 * @since 1.1.0
7 */
8 class WeForms_Field_Manager {
9
10 /**
11 * The fields
12 *
13 * @var array
14 */
15 private $fields = array();
16
17 /**
18 * Get all the registered fields
19 *
20 * @return array
21 */
22 public function get_fields() {
23
24 if ( ! empty( $this->fields ) ) {
25 return $this->fields;
26 }
27
28 $this->register_field_types();
29
30 return $this->fields;
31 }
32
33 /**
34 * Register the field types
35 *
36 * @return void
37 */
38 private function register_field_types() {
39 require_once dirname( __FILE__ ) . '/fields/class-abstract-fields.php';
40
41 require_once dirname( __FILE__ ) . '/fields/class-field-text.php';
42 require_once dirname( __FILE__ ) . '/fields/class-field-name.php';
43 require_once dirname( __FILE__ ) . '/fields/class-field-email.php';
44 require_once dirname( __FILE__ ) . '/fields/class-field-textarea.php';
45 require_once dirname( __FILE__ ) . '/fields/class-field-checkbox.php';
46 require_once dirname( __FILE__ ) . '/fields/class-field-radio.php';
47 require_once dirname( __FILE__ ) . '/fields/class-field-dropdown.php';
48 require_once dirname( __FILE__ ) . '/fields/class-field-multidropdown.php';
49 require_once dirname( __FILE__ ) . '/fields/class-field-url.php';
50 require_once dirname( __FILE__ ) . '/fields/class-field-sectionbreak.php';
51 require_once dirname( __FILE__ ) . '/fields/class-field-html.php';
52 require_once dirname( __FILE__ ) . '/fields/class-field-hidden.php';
53 require_once dirname( __FILE__ ) . '/fields/class-field-image.php';
54 require_once dirname( __FILE__ ) . '/fields/class-field-recaptcha.php';
55
56 $fields = array(
57 'text_field' => new WeForms_Form_Field_Text(),
58 'name_field' => new WeForms_Form_Field_Name(),
59 'email_address' => new WeForms_Form_Field_Email(),
60 'textarea_field' => new WeForms_Form_Field_Textarea(),
61 'radio_field' => new WeForms_Form_Field_Radio(),
62 'checkbox_field' => new WeForms_Form_Field_Checkbox(),
63 'dropdown_field' => new WeForms_Form_Field_Dropdown(),
64 'multiple_select' => new WeForms_Form_Field_MultiDropdown(),
65 'website_url' => new WeForms_Form_Field_URL(),
66 'section_break' => new WeForms_Form_Field_SectionBreak(),
67 'custom_html' => new WeForms_Form_Field_HTML(),
68 'custom_hidden_field' => new WeForms_Form_Field_Hidden(),
69 'image_upload' => new WeForms_Form_Field_Image(),
70 'recaptcha' => new WeForms_Form_Field_reCaptcha(),
71 );
72
73 $this->fields = apply_filters( 'weforms_form_fields', $fields );
74 }
75
76 /**
77 * Get field groups
78 *
79 * @return array
80 */
81 public function get_field_groups() {
82
83 $groups = array(
84 array(
85 'title' => __( 'Custom Fields', 'weforms' ),
86 'id' => 'custom-fields',
87 'fields' => apply_filters( 'weforms_field_groups_custom', array(
88 'name_field', 'text_field', 'textarea_field', 'dropdown_field', 'multiple_select',
89 'radio_field', 'checkbox_field', 'website_url', 'email_address',
90 'custom_hidden_field', 'image_upload'
91 ) )
92 ),
93
94 array(
95 'title' => __( 'Others', 'weforms' ),
96 'id' => 'others',
97 'fields' => apply_filters( 'weforms_field_groups_others', array(
98 'section_break', 'custom_html', 'recaptcha'
99 ) )
100 )
101 );
102
103 return apply_filters( 'weforms_field_groups', $groups );
104 }
105
106 /**
107 * Get fields JS setting for the form builder
108 *
109 * @return array
110 */
111 public function get_js_settings() {
112 $fields = $this->get_fields();
113 $js_array = array();
114
115 if ( $fields ) {
116 foreach ($fields as $type => $object) {
117 $js_array[ $type ] = $object->get_js_settings();
118 }
119 }
120
121 return $js_array;
122 }
123
124 /**
125 * Render the form fields
126 *
127 * @param integer $form_id
128 * @param array $fields
129 *
130 * @return void
131 */
132 public function render_fields( $fields, $form_id ) {
133 if ( ! $fields ) {
134 return;
135 }
136
137 foreach ($fields as $field) {
138 if ( ! $field_object = $this->field_exists( $field['template'] ) ) {
139
140 if ( defined( 'WP_DEBUG' && WP_DEBUG ) ) {
141 echo '<h4 style="color: red;"><em>' . $field['template'] . '</em> field not found.</h4>';
142 }
143
144 continue;
145 }
146
147 $field_object->render( $field, $form_id );
148 $field_object->conditional_logic( $field, $form_id );
149 }
150 }
151
152 /**
153 * Check if a field exists
154 *
155 * @param string $field_type
156 *
157 * @return boolean
158 */
159 public function field_exists( $field_type ) {
160 if ( array_key_exists( $field_type, $this->get_fields() ) ) {
161 return $this->fields[ $field_type ];
162 }
163
164 return false;
165 }
166 }