PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.14
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.14
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/models/FrmField.php +439 -142 6.36.14 View file →
@@ -4,214 +4,231 @@
4 4 }
5 5
6 6 class FrmField {
7 7
8 - public static $use_cache = true;
8 + public static $use_cache = true;
9 9 public static $transient_size = 200;
10 10
11 11 public static function field_selection() {
12 - $frm_settings = FrmAppHelper::get_settings();
13 - $active_captcha = $frm_settings->active_captcha;
14 - if ( ! FrmFieldCaptcha::should_show_captcha() ) {
15 - $captcha_name = 'Captcha';
16 - } elseif ( $active_captcha === 'recaptcha' ) {
17 - $captcha_name = 'reCAPTCHA';
18 - } else {
19 - $captcha_name = 'hCaptcha';
20 - }
21 12 $fields = array(
22 - 'text' => array(
13 + 'text' => array(
23 14 'name' => __( 'Text', 'formidable' ),
24 15 'icon' => 'frm_icon_font frm_text2_icon',
25 16 ),
26 - 'textarea' => array(
17 + 'textarea' => array(
27 18 'name' => __( 'Paragraph', 'formidable' ),
28 19 'icon' => 'frm_icon_font frm_paragraph_icon',
29 20 ),
30 - 'checkbox' => array(
21 + 'checkbox' => array(
31 22 'name' => __( 'Checkboxes', 'formidable' ),
32 23 'icon' => 'frm_icon_font frm_check_square_icon',
33 24 ),
34 - 'radio' => array(
25 + 'radio' => array(
35 26 'name' => __( 'Radio Buttons', 'formidable' ),
36 27 'icon' => 'frm_icon_font frm_radio_checked_icon',
37 28 ),
38 - 'select' => array(
29 + 'select' => array(
39 30 'name' => __( 'Dropdown', 'formidable' ),
40 31 'icon' => 'frm_icon_font frm_caret_square_down_icon',
41 32 ),
42 - 'email' => array(
33 + 'email' => array(
43 34 'name' => __( 'Email', 'formidable' ),
44 35 'icon' => 'frm_icon_font frm_email_icon',
45 36 ),
46 - 'url' => array(
37 + 'url' => array(
47 38 'name' => __( 'Website/URL', 'formidable' ),
48 39 'icon' => 'frm_icon_font frm_link_icon',
49 40 ),
50 - 'number' => array(
41 + 'number' => array(
51 42 'name' => __( 'Number', 'formidable' ),
52 43 'icon' => 'frm_icon_font frm_hashtag_icon',
53 44 ),
54 - 'name' => array(
45 + 'name' => array(
55 46 'name' => __( 'Name', 'formidable' ),
56 47 'icon' => 'frm_icon_font frm_user_name_icon',
57 48 ),
58 - 'phone' => array(
49 + 'phone' => array(
59 50 'name' => __( 'Phone', 'formidable' ),
60 51 'icon' => 'frm_icon_font frm_phone_icon',
61 52 ),
62 - 'html' => array(
53 + 'html' => array(
63 54 'name' => __( 'HTML', 'formidable' ),
64 55 'icon' => 'frm_icon_font frm_code_icon',
65 56 ),
66 - 'hidden' => array(
57 + 'hidden' => array(
67 58 'name' => __( 'Hidden', 'formidable' ),
68 59 'icon' => 'frm_icon_font frm_eye_slash_icon',
69 60 ),
70 - 'user_id' => array(
61 + 'user_id' => array(
71 62 'name' => __( 'User ID', 'formidable' ),
72 63 'icon' => 'frm_icon_font frm_user_icon',
73 64 ),
74 - 'captcha' => array(
75 - 'name' => $captcha_name,
65 + 'captcha' => array(
66 + 'name' => self::get_captcha_field_name(),
76 67 'icon' => 'frm_icon_font frm_shield_check_icon',
77 68 ),
69 + 'credit_card' => array(
70 + 'name' => __( 'Payment', 'formidable' ),
71 + 'icon' => 'frm_icon_font frm_credit_card_icon',
72 + ),
73 + FrmSubmitHelper::FIELD_TYPE => array(
74 + 'name' => __( 'Submit', 'formidable' ),
75 + 'hide' => true,
76 + ),
78 77 );
79 78
79 + /**
80 + * @param array $fields
81 + */
80 82 return apply_filters( 'frm_available_fields', $fields );
81 83 }
82 84
85 + /**
86 + * Get the name of the Captcha field based on the global Captcha setting.
87 + *
88 + * @return string
89 + */
90 + private static function get_captcha_field_name() {
91 + return 'Captcha';
92 + }
93 +
83 94 public static function pro_field_selection() {
84 95 $images_url = FrmAppHelper::plugin_url() . '/images/';
85 96 $fields = array(
86 - 'file' => array(
87 - 'name' => __( 'File Upload', 'formidable' ),
88 - 'icon' => 'frm_icon_font frm_upload_icon',
89 - 'message' => 'Add file uploads to save time and cut down on back-and-forth. Upgrade to Pro to get Upload fields and more.',
97 + 'file' => array(
98 + 'name' => __( 'File Upload', 'formidable' ),
99 + 'icon' => 'frm_icon_font frm_upload_icon',
100 + 'message' => __( 'Add file uploads to save time and cut down on back-and-forth. Upgrade to Pro to get Upload fields and more.', 'formidable' ),
90 101 ),
91 - 'rte' => array(
102 + 'ranking' => array(),
103 + 'rte' => array(
92 104 'name' => __( 'Rich Text', 'formidable' ),
93 105 'icon' => 'frm_icon_font frm_align_right_icon',
94 106 ),
95 - 'date' => array(
107 + 'date' => array(
96 108 'name' => __( 'Date', 'formidable' ),
97 109 'icon' => 'frm_icon_font frm_calendar_icon',
98 110 ),
99 - 'time' => array(
111 + 'time' => array(
100 112 'name' => __( 'Time', 'formidable' ),
101 113 'icon' => 'frm_icon_font frm_clock_icon',
102 114 ),
103 - 'scale' => array(
104 - 'name' => __( 'Scale', 'formidable' ),
105 - 'icon' => 'frm_icon_font frm_linear_scale_icon',
106 - 'message' => 'Add a set of radio buttons with whatever range you choose. <img src="' . esc_attr( $images_url ) . 'scale_field.png" alt="Scale Field" />',
115 + 'scale' => array(
116 + 'name' => __( 'Scale', 'formidable' ),
117 + 'icon' => 'frm_icon_font frm_linear_scale_icon',
118 + 'message' => esc_html__( 'Add a set of radio buttons with whatever range you choose.', 'formidable' ) . '<img src="' . esc_url( $images_url ) . 'scale_field.png" alt="' . esc_attr__( 'Scale Field', 'formidable' ) . '" />',
107 119 ),
108 - 'star' => array(
120 + 'star' => array(
109 121 'name' => __( 'Star Rating', 'formidable' ),
110 122 'icon' => 'frm_icon_font frm_star_icon',
111 123 ),
112 - 'range' => array(
124 + 'range' => array(
113 125 'name' => __( 'Slider', 'formidable' ),
114 126 'icon' => 'frm_icon_font frm_code_commit_icon',
115 127 ),
116 - 'toggle' => array(
128 + 'toggle' => array(
117 129 'name' => __( 'Toggle', 'formidable' ),
118 130 'icon' => 'frm_icon_font frm_toggle_on_icon',
119 131 ),
120 - 'data' => array(
121 - 'name' => __( 'Dynamic', 'formidable' ),
122 - 'icon' => 'frm_icon_font frm_sitemap_icon',
123 - 'message' => 'Create relationships between multiple forms. You can link a member to a team, a rating to a product, a comment to a submission, and much more.',
132 + 'data' => array(
133 + 'name' => __( 'Dynamic', 'formidable' ),
134 + 'icon' => 'frm_icon_font frm_sitemap_icon',
135 + 'message' => __( 'Create relationships between multiple forms. You can link a member to a team, a rating to a product, a comment to a submission, and much more.', 'formidable' ),
124 136 ),
125 - 'lookup' => array(
126 - 'name' => __( 'Lookup', 'formidable' ),
127 - 'icon' => 'frm_icon_font frm_search_icon',
128 - 'message' => 'Filter the options in the next field and automatically add values to other fields. Upgrade to Pro to get Lookup fields and more. <img src="' . esc_attr( $images_url ) . 'look-up_year-make-model.gif" alt="cascading lookup fields" />',
137 + 'lookup' => array(
138 + 'name' => __( 'Lookup', 'formidable' ),
139 + 'icon' => 'frm_icon_font frm_search_icon',
140 + 'message' => esc_html__( 'Filter the options in the next field and automatically add values to other fields. Upgrade to Pro to get Lookup fields and more.', 'formidable' ) . ' <img src="' . esc_url( $images_url ) . 'look-up_year-make-model.gif" alt="' . esc_attr__( 'cascading lookup fields', 'formidable' ) . '" />',
129 141 ),
130 - 'divider|repeat' => array(
131 - 'name' => __( 'Repeater', 'formidable' ),
132 - 'icon' => 'frm_icon_font frm_repeater_icon',
133 - 'message' => 'Allow your visitors to add new sets of fields while filling out forms. Increase conversions while saving building time and server resources. <img src="' . esc_attr( $images_url ) . 'repeatable-section_frontend.gif" alt="Dynamically Add Form Fields with repeatable sections" />',
142 + 'divider|repeat' => array(
143 + 'name' => __( 'Repeater', 'formidable' ),
144 + 'icon' => 'frm_icon_font frm_repeater_icon',
145 + 'message' => esc_html__( 'Allow your visitors to add new sets of fields while filling out forms. Increase conversions while saving building time and server resources.', 'formidable' ) . ' <img src="' . esc_url( $images_url ) . 'repeatable-section_frontend.gif" alt="' . esc_attr__( 'Dynamically Add Form Fields with repeatable sections', 'formidable' ) . '" />',
134 146 ),
135 - 'end_divider' => array(
147 + 'end_divider' => array(
136 148 'name' => __( 'Section Buttons', 'formidable' ),
137 149 'switch_from' => 'divider',
138 150 ),
139 - 'divider' => array(
151 + 'divider' => array(
140 152 'name' => __( 'Section', 'formidable' ),
141 153 'icon' => 'frm_icon_font frm_header_icon',
142 154 ),
143 - 'break' => array(
144 - 'name' => __( 'Page Break', 'formidable' ),
145 - 'icon' => 'frm_icon_font frm_page_break_icon',
146 - 'message' => 'Get multi-paged forms with progress bars. Did you know you can upgrade to PRO to unlock multi-step forms with more awesome features?',
155 + 'break' => array(
156 + 'name' => __( 'Page Break', 'formidable' ),
157 + 'icon' => 'frm_icon_font frm_page_break_icon',
158 + 'message' => __( 'Get multi-paged forms with progress bars. Did you know you can upgrade to PRO to unlock multi-step forms with more awesome features?', 'formidable' ),
147 159 ),
148 - 'form' => array(
160 + 'form' => array(
149 161 'name' => __( 'Embed Form', 'formidable' ),
150 162 'icon' => 'frm_icon_font frm_file_text_icon',
151 163 ),
152 - 'likert' => array(
164 + 'likert' => array(
153 165 'name' => __( 'Likert Scale', 'formidable' ),
154 166 'icon' => 'frm_icon_font frm_likert_scale frm_show_upgrade',
155 167 'addon' => 'surveys',
156 168 ),
157 - 'nps' => array(
169 + 'nps' => array(
158 170 'name' => __( 'NPS', 'formidable' ),
159 171 'icon' => 'frm_icon_font frm_nps frm_show_upgrade',
160 172 'addon' => 'surveys',
161 173 ),
162 - 'password' => array(
174 + 'password' => array(
163 175 'name' => __( 'Password', 'formidable' ),
164 176 'icon' => 'frm_icon_font frm_lock_open_icon',
165 177 ),
166 - 'tag' => array(
178 + 'tag' => array(
167 179 'name' => __( 'Tags', 'formidable' ),
168 180 'icon' => 'frm_icon_font frm_price_tags_icon',
169 181 ),
170 - 'credit_card' => array(
171 - 'name' => __( 'Credit Card', 'formidable' ),
172 - 'icon' => 'frm_icon_font frm_credit_card_icon frm_show_upgrade',
173 - 'addon' => 'stripe',
182 + // This is no longer a Pro field, but without this here, Pro triggers "undefined index" notices.
183 + // Right now it leaves a gap. Maybe we can skip anything without a name or something.
184 + 'credit_card' => array(
185 + 'name' => '',
186 + 'icon' => '',
174 187 ),
175 - 'address' => array(
188 + 'address' => array(
176 189 'name' => __( 'Address', 'formidable' ),
177 190 'icon' => 'frm_icon_font frm_location_icon',
178 191 ),
179 - 'summary' => array(
180 - 'name' => __( 'Summary', 'formidable' ),
181 - 'icon' => 'frm_icon_font frm_file_text_icon',
182 - 'message' => 'Allow visitors to review their responses before a form is submitted. Upgrade to Pro to get Summary fields and more.',
192 + 'summary' => array(
193 + 'name' => __( 'Summary', 'formidable' ),
194 + 'icon' => 'frm_icon_font frm_file_text_icon',
195 + 'message' => __( 'Allow visitors to review their responses before a form is submitted. Upgrade to Pro to get Summary fields and more.', 'formidable' ),
183 196 ),
184 - 'signature' => array(
197 + 'signature' => array(
185 198 'name' => __( 'Signature', 'formidable' ),
186 199 'icon' => 'frm_icon_font frm_signature_icon frm_show_upgrade',
187 200 'addon' => 'signature',
188 201 ),
189 - 'ai' => array(
190 - 'name' => __( 'AI', 'formidable' ),
191 - 'icon' => 'frm_icon_font frm_eye_icon frm_show_upgrade',
192 - 'addon' => 'ai',
193 - 'message' => 'Streamline workflows and reclaim valuable time with the power of AI. You can effortlessly respond to your visitors in real-time with ChatGPT as your automated assistant. Upgrade to Pro and unlock AI-powered fields.',
202 + 'ai' => array(
203 + 'name' => __( 'AI', 'formidable' ),
204 + 'icon' => 'frm_icon_font frm_eye_icon frm_show_upgrade',
205 + 'addon' => 'ai',
206 + 'message' => __( 'Streamline workflows and reclaim valuable time with the power of AI. You can effortlessly respond to your visitors in real-time with ChatGPT as your automated assistant. Upgrade to Pro and unlock AI-powered fields.', 'formidable' ),
194 207 ),
195 208 'ssa-appointment' => array(
196 209 'name' => __( 'Appointment', 'formidable' ),
197 210 'icon' => 'frm_icon_font frm_calendar_icon frm_show_upgrade',
198 211 'require' => 'Simply Schedule Appointments',
199 - 'message' => 'Appointment fields are an integration with <a href="https://simplyscheduleappointments.com/meet/formidable/">Simply Schedule Appointments</a>. Get started now to schedule appointments directly from your forms.
200 - <img src="' . esc_attr( $images_url ) . 'appointments.png" alt="Scheduling" />',
212 + 'message' => sprintf(
213 + /* translators: %1$s: Link opening HTML, %2$s: Link tag closing */
214 + esc_html__( 'Appointment fields are an integration with %1$sSimply Schedule Appointments%2$s. Get started now to schedule appointments directly from your forms.', 'formidable' ),
215 + '<a href="https://simplyscheduleappointments.com/meet/formidable/">',
216 + '</a>'
217 + ) . '<img src="' . esc_url( $images_url ) . 'appointments.png" alt="' . esc_attr__( 'Scheduling', 'formidable' ) . '" />',
201 218 'link' => 'https://simplyscheduleappointments.com/meet/formidable/',
202 219 ),
203 - 'product' => array(
220 + 'product' => array(
204 221 'name' => __( 'Product', 'formidable' ),
205 222 'icon' => 'frm_icon_font frm_product_icon',
206 223 'section' => 'pricing',
207 224 ),
208 - 'quantity' => array(
225 + 'quantity' => array(
209 226 'name' => __( 'Quantity', 'formidable' ),
210 227 'icon' => 'frm_icon_font frm_quantity_icon',
211 228 'section' => 'pricing',
212 229 ),
213 - 'total' => array(
230 + 'total' => array(
214 231 'name' => __( 'Total', 'formidable' ),
215 232 'icon' => 'frm_icon_font frm_total_icon',
216 233 'section' => 'pricing',
217 234 ),
@@ -216,8 +233,21 @@
216 233 'section' => 'pricing',
217 234 ),
218 235 );
219 236
237 + if ( self::include_ranking_fields() ) {
238 + $fields['ranking'] = array(
239 + 'name' => __( 'Ranking', 'formidable' ),
240 + 'icon' => 'frm_icon_font frm_chart_bar_icon frm_show_upgrade',
241 + 'message' => __( 'Now you can effortlessly gather insights, preferences, and opinions by allowing users to rank options.', 'formidable' ),
242 + 'upsell_image' => esc_url( $images_url ) . 'ranking-field.svg',
243 + 'addon' => 'surveys',
244 + 'is_new' => self::field_is_new( 'ranking' ),
245 + );
246 + } else {
247 + unset( $fields['ranking'] );
248 + }
249 +
220 250 if ( ! FrmAppHelper::show_new_feature( 'ai' ) ) {
221 251 unset( $fields['ai'] );
222 252 }
223 253
@@ -230,9 +260,102 @@
230 260 return apply_filters( 'frm_pro_available_fields', $fields );
231 261 }
232 262
233 263 /**
264 + * Check if we should show ranking fields in the builder.
265 + * This is based on the active version coming from our API data.
266 + * If Surveys v1.1 is not released yet, we don't want to display ranking fields yet.
267 + *
268 + * @since 6.8.3
269 + *
270 + * @return bool
271 + */
272 + private static function include_ranking_fields() {
273 + if ( class_exists( 'FrmSurveys\models\fields\Ranking' ) ) {
274 + // Always return true if Ranking fields exist.
275 + return true;
276 + }
277 +
278 + $plugin = 'formidable-surveys/formidable-surveys.php';
279 + $expected_version = '1.1';
280 +
281 + return self::installed_plugin_meets_version( $plugin, $expected_version ) || self::api_meets_version( $plugin, $expected_version );
282 + }
283 +
284 + /**
285 + * @since 6.8.3
286 + *
287 + * @param string $plugin
288 + * @param string $expected_version
289 + * @return bool
290 + */
291 + private static function installed_plugin_meets_version( $plugin, $expected_version ) {
292 + $installed_version = self::get_installed_version( $plugin );
293 + return $installed_version && version_compare( $installed_version, $expected_version, '>=' );
294 + }
295 +
296 + /**
297 + * @since 6.8.3
298 + *
299 + * @param string $plugin
300 + * @return false|string String version. False if the plugin is not installed.
301 + */
302 + private static function get_installed_version( $plugin ) {
303 + if ( ! function_exists( 'get_plugins' ) ) {
304 + require_once ABSPATH . 'wp-admin/includes/plugin.php';
305 + }
306 + $plugins = get_plugins();
307 + if ( isset( $plugins[ $plugin ] ) && ! empty( $plugins[ $plugin ]['Version'] ) ) {
308 + return $plugins[ $plugin ]['Version'];
309 + }
310 + return false;
311 + }
312 +
313 + /**
314 + * @since 6.8.3
315 + *
316 + * @param string $plugin
317 + * @param string $expected_version
318 + * @return bool
319 + */
320 + private static function api_meets_version( $plugin, $expected_version ) {
321 + $api = new FrmFormApi();
322 + $addons = $api->get_api_info();
323 + $matches = wp_list_filter( $addons, array( 'plugin' => $plugin ) );
324 + if ( ! $matches ) {
325 + return false;
326 + }
327 +
328 + $match = reset( $matches );
329 + if ( empty( $match['new_version'] ) ) {
330 + return false;
331 + }
332 +
333 + $api_version = $match['new_version'];
334 + return version_compare( $api_version, $expected_version, '>=' );
335 + }
336 +
337 + /**
338 + * Consider a field new for 90 days after the release date.
339 + *
340 + * @since 6.8.3
341 + *
342 + * @param string $type
343 + * @return bool
344 + */
345 + private static function field_is_new( $type ) {
346 + if ( 'ranking' === $type ) {
347 + $ranking_release_date = '2024-03-12';
348 + $three_months_after_release = gmdate( 'Y-m-d', strtotime( $ranking_release_date . ' + 90 days' ) );
349 + return gmdate( 'Y-m-d' ) < $three_months_after_release;
350 + }
351 + return false;
352 + }
353 +
354 + /**
234 355 * @since 4.0
356 + *
357 + * @return array
235 358 */
236 359 public static function all_field_selection() {
237 360 $pro_field_selection = self::pro_field_selection();
238 361 return array_merge( $pro_field_selection, self::field_selection() );
@@ -237,8 +360,15 @@
237 360 $pro_field_selection = self::pro_field_selection();
238 361 return array_merge( $pro_field_selection, self::field_selection() );
239 362 }
240 363
364 + /**
365 + * Create a field.
366 + *
367 + * @param array $values
368 + * @param bool $return
369 + * @return false|int
370 + */
241 371 public static function create( $values, $return = true ) {
242 372 global $wpdb, $frm_duplicate_ids;
243 373
244 374 $new_values = array();
@@ -276,30 +406,32 @@
276 406 unset( $k, $v );
277 407 }
278 408
279 409 $query_results = $wpdb->insert( $wpdb->prefix . 'frm_fields', $new_values );
280 - $new_id = 0;
281 - if ( $query_results ) {
282 - self::delete_form_transient( $new_values['form_id'] );
283 - $new_id = $wpdb->insert_id;
410 +
411 + if ( ! $query_results ) {
412 + return false;
284 413 }
285 414
415 + self::delete_form_transient( $new_values['form_id'] );
416 + $new_id = $wpdb->insert_id;
417 +
286 418 if ( ! $return ) {
287 419 return false;
288 420 }
289 421
290 - if ( $query_results ) {
291 - if ( isset( $values['id'] ) ) {
292 - $frm_duplicate_ids[ $values['id'] ] = $new_id;
293 - }
422 + if ( isset( $values['id'] ) ) {
423 + $frm_duplicate_ids[ $values['id'] ] = $new_id;
424 + }
294 425
295 - return $new_id;
296 - } else {
297 - return false;
298 - }
426 + return $new_id;
299 427 }
300 428
301 429 /**
430 + * Maybe filter HTML in field options data.
431 + * HTML is only filtered when unsafe HTML is disallowed.
432 + * See FrmAppHelper::allow_unfiltered_html.
433 + *
302 434 * @since 5.0.08
303 435 *
304 436 * @param array $options
305 437 * @return array
@@ -304,12 +436,78 @@
304 436 * @param array $options
305 437 * @return array
306 438 */
307 439 private static function maybe_filter_options( $options ) {
308 - return FrmAppHelper::maybe_filter_array( $options, array( 'custom_html' ) );
440 + $options = FrmAppHelper::maybe_filter_array( $options, array( 'custom_html' ) );
441 +
442 + if ( ! empty( $options['custom_html'] ) ) {
443 + $options['custom_html'] = self::maybe_filter_custom_html_input_attributes( $options['custom_html'] );
444 + }
445 +
446 + return $options;
309 447 }
310 448
311 449 /**
450 + * Prevent users who do not have permission to insert JavaScript attributes in input elements.
451 + * This is triggered when a field is updated.
452 + *
453 + * @since 6.11.2
454 + *
455 + * @param string $html
456 + * @return string
457 + */
458 + private static function maybe_filter_custom_html_input_attributes( $html ) {
459 + if ( FrmAppHelper::allow_unfiltered_html() ) {
460 + return $html;
461 + }
462 +
463 + $pattern = get_shortcode_regex( array( 'input' ) );
464 + return preg_replace_callback(
465 + "/$pattern/",
466 + /**
467 + * @param array $match Shortcode data.
468 + * @return string
469 + */
470 + function ( $match ) {
471 + $attr = shortcode_parse_atts( $match[3] );
472 +
473 + if ( ! is_array( $attr ) ) {
474 + // In old versions of WordPress (older than 6.5), this might not be an array.
475 + return '[input]';
476 + }
477 +
478 + $safe_atts = array();
479 + foreach ( $attr as $attr_key => $att ) {
480 + if ( ! is_numeric( $attr_key ) ) {
481 + // opt=1 without parentheses for example is mapped like 'opt' => 1.
482 + $key = $attr_key;
483 + $value = $att;
484 + } else {
485 + // Some data is mapped like 0 => 'placeholder="Placeholder"'.
486 + $split = explode( '=', $att, 2 );
487 + if ( 2 !== count( $split ) ) {
488 + continue;
489 + }
490 + $key = trim( $split[0] );
491 + $value = trim( $split[1], '"' );
492 + }
493 +
494 + if ( FrmAppHelper::input_key_is_safe( $key, 'update' ) ) {
495 + $safe_atts[ $key ] = $value;
496 + }
497 + }
498 +
499 + if ( ! $safe_atts ) {
500 + return '[input]';
501 + }
502 +
503 + return '[input ' . FrmAppHelper::array_to_html_params( $safe_atts ) . ']';
504 + },
505 + $html
506 + );
507 + }
508 +
509 + /**
312 510 * Process the field duplication.
313 511 *
314 512 * @since 5.0.05
315 513 */
@@ -400,11 +598,16 @@
400 598 $new_id = self::create( $values );
401 599 $frm_duplicate_ids[ $field->id ] = $new_id;
402 600 $frm_duplicate_ids[ $field->field_key ] = $new_id;
403 601 unset( $field );
404 - }
602 + }//end foreach
405 603 }
406 604
605 + /**
606 + * @param int|string $id
607 + * @param array $values
608 + * @return false|int
609 + */
407 610 public static function update( $id, $values ) {
408 611 global $wpdb;
409 612
410 613 $id = absint( $id );
@@ -420,10 +623,22 @@
420 623
421 624 self::preserve_format_option_backslashes( $values );
422 625
423 626 if ( isset( $values['type'] ) ) {
424 - $values = apply_filters( 'frm_clean_' . $values['type'] . '_field_options_before_update', $values );
627 + if ( 'dropdown' === $values['type'] ) {
628 + // To avoid conflicts with security plugins the value "dropdown" is sent for select fields.
629 + // This is because "select" gets matched for SQL injection attempts.
630 + $values['type'] = 'select';
631 + }
425 632
633 + /**
634 + * @since 6.9 The Field ID param was added.
635 + *
636 + * @param array $values
637 + * @param int $id Field ID.
638 + */
639 + $values = apply_filters( 'frm_clean_' . $values['type'] . '_field_options_before_update', $values, $id );
640 +
426 641 if ( $values['type'] === 'hidden' && isset( $values['field_options'] ) && isset( $values['field_options']['clear_on_focus'] ) ) {
427 642 // don't keep the old placeholder setting for hidden fields
428 643 $values['field_options']['clear_on_focus'] = 0;
429 644 }
@@ -470,9 +685,9 @@
470 685 * Keep backslashes in the phone format option
471 686 *
472 687 * @since 2.0.8
473 688 *
474 - * @param $values array - pass by reference
689 + * @param array $values Pass by reference.
475 690 */
476 691 private static function preserve_format_option_backslashes( &$values ) {
477 692 if ( isset( $values['field_options']['format'] ) ) {
478 693 $values['field_options']['format'] = FrmAppHelper::preserve_backslashes( $values['field_options']['format'] );
@@ -516,8 +731,11 @@
516 731 }
517 732
518 733 /**
519 734 * If $field is numeric, get the field object
735 + *
736 + * @param int|object|string $field
737 + * @return void
520 738 */
521 739 public static function maybe_get_field( &$field ) {
522 740 if ( ! is_object( $field ) ) {
523 741 $field = self::getOne( $field );
@@ -524,10 +742,10 @@
524 742 }
525 743 }
526 744
527 745 /**
528 - * @param string|int $id The field id or key.
529 - * @param bool $filter When true, run the frm_field filter.
746 + * @param int|string $id The field id or key.
747 + * @param bool $filter When true, run the frm_field filter.
530 748 */
531 749 public static function getOne( $id, $filter = false ) {
532 750 if ( empty( $id ) ) {
533 751 return null;
@@ -573,10 +791,10 @@
573 791
574 792 /**
575 793 * Get the field type by key or id
576 794 *
577 - * @param int|string The field id or key
578 - * @param mixed $col The name of the column in the fields database table
795 + * @param int|string $id The field id or key.
796 + * @param mixed $col The name of the column in the fields database table.
579 797 */
580 798 public static function get_type( $id, $col = 'type' ) {
581 799 $field = FrmDb::check_cache( $id, 'frm_field' );
582 800 if ( $field ) {
@@ -592,8 +810,14 @@
592 810
593 811 return $type;
594 812 }
595 813
814 + /**
815 + * @param int|string $form_id
816 + * @param string $type
817 + * @param int|string $limit
818 + * @param string $inc_sub
819 + */
596 820 public static function get_all_types_in_form( $form_id, $type, $limit = '', $inc_sub = 'exclude' ) {
597 821 if ( ! $form_id ) {
598 822 return array();
599 823 }
@@ -613,9 +837,9 @@
613 837 continue;
614 838 }
615 839
616 840 $fields[ $result->id ] = $result;
617 - $count ++;
841 + ++$count;
618 842 if ( $limit == 1 ) {
619 843 $fields = $result;
620 844 break;
621 845 }
@@ -627,9 +851,9 @@
627 851 unset( $result );
628 852 }
629 853
630 854 return wp_unslash( $fields );
631 - }
855 + }//end if
632 856
633 857 self::$use_cache = false;
634 858
635 859 $where = array(
@@ -643,8 +867,15 @@
643 867
644 868 return $results;
645 869 }
646 870
871 + /**
872 + * @param int|string $form_id
873 + * @param int|string $limit
874 + * @param string $inc_embed
875 + * @param string $inc_repeat
876 + * @return array
877 + */
647 878 public static function get_all_for_form( $form_id, $limit = '', $inc_embed = 'exclude', $inc_repeat = 'include' ) {
648 879 if ( ! (int) $form_id ) {
649 880 return array();
650 881 }
@@ -657,9 +888,9 @@
657 888
658 889 $fields = array();
659 890 $count = 0;
660 891 foreach ( $results as $result ) {
661 - $count ++;
892 + ++$count;
662 893 $fields[ $result->id ] = $result;
663 894 if ( ! empty( $limit ) && $count >= $limit ) {
664 895 break;
665 896 }
@@ -688,12 +919,12 @@
688 919 /**
689 920 * If repeating fields should be included, adjust $where accordingly
690 921 *
691 922 * @param string $inc_repeat
692 - * @param array $where - pass by reference
923 + * @param array $where Pass by reference.
693 924 */
694 925 private static function maybe_include_repeating_fields( $inc_repeat, &$where ) {
695 - if ( $inc_repeat == 'include' ) {
926 + if ( $inc_repeat === 'include' ) {
696 927 $form_id = $where['fi.form_id'];
697 928 $where[] = array(
698 929 'or' => 1,
699 930 'fi.form_id' => $form_id,
@@ -708,9 +939,9 @@
708 939 if ( 'include' != $inc_embed || $no_sub_forms ) {
709 940 return;
710 941 }
711 942
712 - $form_fields = $results;
943 + $form_fields = $results;
713 944 $should_get_subforms = ( $type !== 'all' && $type !== 'form' && ! empty( $form_id ) );
714 945 if ( $should_get_subforms ) {
715 946 $form_fields = self::get_all_types_in_form( $form_id, 'form' );
716 947 }
@@ -720,9 +951,9 @@
720 951 if ( 'form' != $field->type || ! isset( $field->field_options['form_select'] ) ) {
721 952 continue;
722 953 }
723 954
724 - if ( $type == 'all' ) {
955 + if ( $type === 'all' ) {
725 956 $sub_fields = self::get_all_for_form( $field->field_options['form_select'] );
726 957 } else {
727 958 $sub_fields = self::get_all_types_in_form( $field->field_options['form_select'], $type );
728 959 }
@@ -727,9 +958,9 @@
727 958 $sub_fields = self::get_all_types_in_form( $field->field_options['form_select'], $type );
728 959 }
729 960
730 961 if ( ! empty( $sub_fields ) ) {
731 - $index = $k + $index_offset;
962 + $index = $k + $index_offset;
732 963 $index_offset += count( $sub_fields );
733 964 array_splice( $results, $index, 0, $sub_fields );
734 965 }
735 966 unset( $field, $sub_fields );
@@ -769,9 +1000,9 @@
769 1000
770 1001 $limit = FrmDb::esc_limit( $limit );
771 1002
772 1003 $query = "SELECT fi.*, fr.name as form_name FROM {$table_name} fi LEFT OUTER JOIN {$form_table_name} fr ON fi.form_id=fr.id";
773 - $query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results';
1004 + $query_type = $limit === ' LIMIT 1' || $limit == 1 ? 'row' : 'results';
774 1005
775 1006 if ( is_array( $where ) ) {
776 1007 $args = array(
777 1008 'order_by' => $order_by,
@@ -781,9 +1012,9 @@
781 1012 } else {
782 1013 // if the query is not an array, then it has already been prepared
783 1014 $query .= FrmDb::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
784 1015
785 - $function_name = ( $query_type == 'row' ) ? 'get_row' : 'get_results';
1016 + $function_name = $query_type === 'row' ? 'get_row' : 'get_results';
786 1017 $results = $wpdb->$function_name( $query );
787 1018 }
788 1019 unset( $where );
789 1020
@@ -835,9 +1066,9 @@
835 1066 }
836 1067 }
837 1068
838 1069 /**
839 - * If a form has too many fields, thay won't all save into a single transient.
1070 + * If a form has too many fields, they won't all save into a single transient.
840 1071 * We'll break them into groups of 200
841 1072 *
842 1073 * @since 2.0.1
843 1074 */
@@ -861,9 +1092,9 @@
861 1092 $fields = array_merge( $fields, $next_fields );
862 1093
863 1094 if ( count( $next_fields ) >= self::$transient_size ) {
864 1095 // if this transient is full, check for another
865 - $next ++;
1096 + ++$next;
866 1097 self::get_next_transient( $fields, $base_name, $next );
867 1098 }
868 1099 }
869 1100 }
@@ -889,18 +1120,25 @@
889 1120
890 1121 return;
891 1122 }
892 1123
893 - $next ++;
1124 + ++$next;
894 1125 }
895 1126 }
896 1127
1128 + /**
1129 + * @param string $type
1130 + * @return bool
1131 + */
897 1132 public static function is_no_save_field( $type ) {
898 - return in_array( $type, self::no_save_fields() );
1133 + return in_array( $type, self::no_save_fields(), true );
899 1134 }
900 1135
1136 + /**
1137 + * @return string[]
1138 + */
901 1139 public static function no_save_fields() {
902 - return array( 'divider', 'end_divider', 'captcha', 'break', 'html', 'form', 'summary' );
1140 + return array( 'divider', 'end_divider', 'captcha', 'break', 'html', 'form', 'summary', FrmSubmitHelper::FIELD_TYPE );
903 1141 }
904 1142
905 1143 /**
906 1144 * Check if this field can hold an array of values
@@ -908,9 +1146,9 @@
908 1146 * @since 2.0.9
909 1147 *
910 1148 * @param array|object $field
911 1149 *
912 - * @return boolean
1150 + * @return bool
913 1151 */
914 1152 public static function is_field_with_multiple_values( $field ) {
915 1153 if ( ! $field ) {
916 1154 return false;
@@ -919,9 +1157,9 @@
919 1157 $field_type = self::get_original_field_type( $field );
920 1158
921 1159 $is_multi_value_field = (
922 1160 self::is_checkbox( $field ) ||
923 - $field_type == 'address' ||
1161 + $field_type === 'address' ||
924 1162 self::is_multiple_select( $field )
925 1163 );
926 1164
927 1165 return $is_multi_value_field;
@@ -928,8 +1166,9 @@
928 1166 }
929 1167
930 1168 /**
931 1169 * @since 3.0
1170 + * @param array|object $field
932 1171 * @return string
933 1172 */
934 1173 public static function get_field_type( $field ) {
935 1174 return is_array( $field ) ? $field['type'] : $field->type;
@@ -943,9 +1182,10 @@
943 1182 $field_type = self::get_field_type( $field );
944 1183 $original_type = self::get_option( $field, 'original_type' );
945 1184
946 1185 if ( ! empty( $original_type ) && $original_type != $field_type ) {
947 - $field_type = $original_type; // check the original type for arrays
1186 + // Check the original type for arrays.
1187 + $field_type = $original_type;
948 1188 }
949 1189
950 1190 return $field_type;
951 1191 }
@@ -953,9 +1193,9 @@
953 1193 /**
954 1194 * Check if this is a multiselect dropdown field
955 1195 *
956 1196 * @since 2.0.9
957 - * @return boolean
1197 + * @return bool
958 1198 */
959 1199 public static function is_multiple_select( $field ) {
960 1200 $field_type = self::get_field_type( $field );
961 1201 $is_multiple = self::is_option_true( $field, 'multiple' ) && self::is_field_type( $field, 'select' ) && $field_type !== 'hidden';
@@ -967,63 +1207,104 @@
967 1207 * Check if a field is read only. Read only can be set in the field options,
968 1208 * but disabled with the shortcode options
969 1209 *
970 1210 * @since 2.0.9
1211 + *
1212 + * @param array|object $field
1213 + * @return bool
971 1214 */
972 1215 public static function is_read_only( $field ) {
973 1216 global $frm_vars;
974 -
975 - return ( self::is_option_true( $field, 'read_only' ) && ( ! isset( $frm_vars['readonly'] ) || $frm_vars['readonly'] != 'disabled' ) );
1217 + return self::is_option_true( $field, 'read_only' ) && ( ! isset( $frm_vars['readonly'] ) || $frm_vars['readonly'] !== 'disabled' );
976 1218 }
977 1219
978 1220 /**
979 1221 * @since 2.0.9
1222 + *
1223 + * @param array $field
1224 + * @return bool
980 1225 */
981 1226 public static function is_required( $field ) {
982 - $required = ( $field['required'] != '0' );
983 - $required = apply_filters( 'frm_is_field_required', $required, $field );
1227 + $required = $field['required'] != '0';
984 1228
1229 + /**
1230 + * @param bool $required
1231 + * @param array $field
1232 + */
1233 + $required = (bool) apply_filters( 'frm_is_field_required', $required, $field );
1234 +
985 1235 return $required;
986 1236 }
987 1237
988 1238 /**
989 1239 * @since 2.0.9
1240 + *
1241 + * @param array|object $field
1242 + * @param string $option
1243 + * @return bool
990 1244 */
991 1245 public static function is_option_true( $field, $option ) {
992 1246 if ( is_array( $field ) ) {
993 1247 return self::is_option_true_in_array( $field, $option );
994 - } else {
995 - return self::is_option_true_in_object( $field, $option );
996 1248 }
1249 + return self::is_option_true_in_object( $field, $option );
997 1250 }
998 1251
999 1252 /**
1000 1253 * @since 2.0.9
1254 + *
1255 + * @param array|object $field
1256 + * @param string $option
1257 + * @return bool
1001 1258 */
1002 1259 public static function is_option_empty( $field, $option ) {
1003 1260 if ( is_array( $field ) ) {
1004 1261 return self::is_option_empty_in_array( $field, $option );
1005 - } else {
1006 - return self::is_option_empty_in_object( $field, $option );
1007 1262 }
1263 + return self::is_option_empty_in_object( $field, $option );
1008 1264 }
1009 1265
1266 + /**
1267 + * @param array $field
1268 + * @param string $option
1269 + * @return bool
1270 + */
1010 1271 public static function is_option_true_in_array( $field, $option ) {
1011 - return isset( $field[ $option ] ) && $field[ $option ];
1272 + return ! empty( $field[ $option ] );
1012 1273 }
1013 1274
1275 + /**
1276 + * @param object $field
1277 + * @param string $option
1278 + * @return bool
1279 + */
1014 1280 public static function is_option_true_in_object( $field, $option ) {
1015 1281 return isset( $field->field_options[ $option ] ) && $field->field_options[ $option ];
1016 1282 }
1017 1283
1284 + /**
1285 + * @param array $field
1286 + * @param string $option
1287 + * @return bool
1288 + */
1018 1289 public static function is_option_empty_in_array( $field, $option ) {
1019 - return ! isset( $field[ $option ] ) || empty( $field[ $option ] );
1290 + return empty( $field[ $option ] );
1020 1291 }
1021 1292
1293 + /**
1294 + * @param object $field
1295 + * @param string $option
1296 + * @return bool
1297 + */
1022 1298 public static function is_option_empty_in_object( $field, $option ) {
1023 - return ! isset( $field->field_options[ $option ] ) || empty( $field->field_options[ $option ] );
1299 + return empty( $field->field_options[ $option ] );
1024 1300 }
1025 1301
1302 + /**
1303 + * @param stdClass $field
1304 + * @param string $option
1305 + * @return bool
1306 + */
1026 1307 public static function is_option_value_in_object( $field, $option ) {
1027 1308 return isset( $field->field_options[ $option ] ) && $field->field_options[ $option ] != '';
1028 1309 }
1029 1310
@@ -1028,8 +1309,12 @@
1028 1309 }
1029 1310
1030 1311 /**
1031 1312 * @since 2.0.18
1313 + *
1314 + * @param array|object $field
1315 + * @param string $option
1316 + * @return mixed
1032 1317 */
1033 1318 public static function get_option( $field, $option ) {
1034 1319 if ( is_array( $field ) ) {
1035 1320 $option = self::get_option_in_array( $field, $option );
@@ -1039,10 +1324,14 @@
1039 1324
1040 1325 return $option;
1041 1326 }
1042 1327
1328 + /**
1329 + * @param array $field
1330 + * @param string $option
1331 + * @return mixed
1332 + */
1043 1333 public static function get_option_in_array( $field, $option ) {
1044 -
1045 1334 if ( isset( $field[ $option ] ) ) {
1046 1335 $this_option = $field[ $option ];
1047 1336 } elseif ( isset( $field['field_options'] ) && is_array( $field['field_options'] ) && isset( $field['field_options'][ $option ] ) ) {
1048 1337 $this_option = $field['field_options'][ $option ];
@@ -1052,8 +1341,13 @@
1052 1341
1053 1342 return $this_option;
1054 1343 }
1055 1344
1345 + /**
1346 + * @param object $field
1347 + * @param string $option
1348 + * @return mixed
1349 + */
1056 1350 public static function get_option_in_object( $field, $option ) {
1057 1351 return isset( $field->field_options[ $option ] ) ? $field->field_options[ $option ] : '';
1058 1352 }
1059 1353
@@ -1058,17 +1352,20 @@
1058 1352 }
1059 1353
1060 1354 /**
1061 1355 * @since 2.0.09
1356 + *
1357 + * @param array|object $field
1358 + * @return bool
1062 1359 */
1063 1360 public static function is_repeating_field( $field ) {
1064 1361 if ( is_array( $field ) ) {
1065 - $is_repeating_field = ( 'divider' == $field['type'] );
1362 + $is_repeating_field = ( 'divider' === $field['type'] );
1066 1363 } else {
1067 - $is_repeating_field = ( 'divider' == $field->type );
1364 + $is_repeating_field = ( 'divider' === $field->type );
1068 1365 }
1069 1366
1070 - return ( $is_repeating_field && self::is_option_true( $field, 'repeat' ) );
1367 + return $is_repeating_field && self::is_option_true( $field, 'repeat' );
1071 1368 }
1072 1369
1073 1370 /**
1074 1371 * @param string $key
@@ -1083,9 +1380,9 @@
1083 1380
1084 1381 /**
1085 1382 * @param string $id
1086 1383 *
1087 - * @return null|string
1384 + * @return string|null
1088 1385 */
1089 1386 public static function get_key_by_id( $id ) {
1090 1387 return FrmDb::get_var( 'frm_fields', array( 'id' => $id ), 'field_key' );
1091 1388 }
@@ -1092,9 +1389,9 @@
1092 1389
1093 1390 public static function is_image( $field ) {
1094 1391 $type = self::get_field_type( $field );
1095 1392
1096 - return ( $type == 'url' && self::get_option( $field, 'show_image' ) );
1393 + return ( $type === 'url' && self::get_option( $field, 'show_image' ) );
1097 1394 }
1098 1395
1099 1396 /**
1100 1397 * Check if field is radio or Dynamic radio
@@ -1102,9 +1399,9 @@
1102 1399 * @since 3.0
1103 1400 *
1104 1401 * @param array|object $field
1105 1402 *
1106 - * @return boolean true if field type is radio or Dynamic radio
1403 + * @return bool true if field type is radio or Dynamic radio
1107 1404 */
1108 1405 public static function is_radio( $field ) {
1109 1406 return self::is_field_type( $field, 'radio' );
1110 1407 }
@@ -1115,9 +1412,9 @@
1115 1412 * @since 3.0
1116 1413 *
1117 1414 * @param array|object $field
1118 1415 *
1119 - * @return boolean true if field type is checkbox or Dynamic checkbox
1416 + * @return bool true if field type is checkbox or Dynamic checkbox
1120 1417 */
1121 1418 public static function is_checkbox( $field ) {
1122 1419 return self::is_field_type( $field, 'checkbox' );
1123 1420 }
@@ -1127,11 +1424,11 @@
1127 1424 *
1128 1425 * @since 3.0
1129 1426 *
1130 1427 * @param array|object $field
1131 - * @param string $is_type Options include radio, checkbox, text
1428 + * @param string $is_type Options include radio, checkbox, text.
1132 1429 *
1133 - * @return boolean true if field type is checkbox or Dynamic checkbox
1430 + * @return bool true if field type is checkbox or Dynamic checkbox
1134 1431 */
1135 1432 public static function is_field_type( $field, $is_type ) {
1136 1433 $field_type = self::get_original_field_type( $field );
1137 1434 $data_type = self::get_option( $field, 'data_type' );