PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.8.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.8.1
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/helpers/FrmOnSubmitHelper.php +59 -85 6.32 → 6.8.1 View file →
@@ -2,9 +2,8 @@
2 2 /**
3 3 * On Submit action helper
4 4 *
5 5 * @package Formidable
6 - *
7 6 * @since 6.0
8 7 */
9 8
10 9 if ( ! defined( 'ABSPATH' ) ) {
@@ -24,16 +23,13 @@
24 23 * @type object $form Form data.
25 24 * @type string $action_key Action key.
26 25 * @type array $values Contains `fields` (form fields) and `id` (form ID).
27 26 * }
28 - *
29 - * @return void
30 27 */
31 28 public static function show_message_settings( $args ) {
32 29 $id_attr = $args['action_control']->get_field_id( 'success_msg' );
33 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
34 30 ?>
35 - <div class="frm_form_field frm_has_shortcodes frm-mt-sm">
31 + <div class="frm_form_field frm_has_shortcodes">
36 32 <label for="<?php echo esc_attr( $id_attr ); ?>" class="screen-reader-text">
37 33 <?php esc_html_e( 'Message on submit', 'formidable' ); ?>
38 34 </label>
39 35
@@ -53,9 +49,9 @@
53 49 <?php
54 50 $id_attr = $args['action_control']->get_field_id( 'show_form' );
55 51 $name_attr = $args['action_control']->get_field_name( 'show_form' );
56 52 ?>
57 - <div class="frm_form_field frm-h-stack-xs">
53 + <div class="frm_form_field">
58 54 <?php
59 55 FrmHtmlHelper::toggle(
60 56 $id_attr,
61 57 $name_attr,
@@ -70,9 +66,8 @@
70 66 <?php esc_html_e( 'Show the form with the confirmation message', 'formidable' ); ?>
71 67 </label>
72 68 </div>
73 69 <?php
74 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
75 70 }
76 71
77 72 /**
78 73 * Shows redirect settings.
@@ -85,13 +80,43 @@
85 80 * @type object $form Form data.
86 81 * @type string $action_key Action key.
87 82 * @type array $values Contains `fields` (form fields) and `id` (form ID).
88 83 * }
89 - *
90 - * @return void
91 84 */
92 85 public static function show_redirect_settings( $args ) {
93 - include FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/on_submit_redirect_settings.php';
86 + $id_attr = $args['action_control']->get_field_id( 'success_url' );
87 + ?>
88 + <div class="frm_form_field frm_has_shortcodes">
89 + <label for="<?php echo esc_attr( $id_attr ); ?>"><?php esc_html_e( 'Redirect URL', 'formidable' ); ?></label>
90 + <input
91 + type="text"
92 + id="<?php echo esc_attr( $id_attr ); ?>"
93 + name="<?php echo esc_attr( $args['action_control']->get_field_name( 'success_url' ) ); ?>"
94 + value="<?php echo esc_attr( $args['form_action']->post_content['success_url'] ); ?>"
95 + />
96 + </div>
97 +
98 + <?php
99 + $id_attr = $args['action_control']->get_field_id( 'open_in_new_tab' );
100 + $name_attr = $args['action_control']->get_field_name( 'open_in_new_tab' );
101 + ?>
102 + <div class="frm_form_field">
103 + <?php
104 + FrmHtmlHelper::toggle(
105 + $id_attr,
106 + $name_attr,
107 + array(
108 + 'div_class' => 'with_frm_style frm_toggle',
109 + 'checked' => ! empty( $args['form_action']->post_content['open_in_new_tab'] ),
110 + 'echo' => true,
111 + )
112 + );
113 + ?>
114 + <label for="<?php echo esc_attr( $id_attr ); ?>" <?php FrmAppHelper::maybe_add_tooltip( 'new_tab' ); ?>>
115 + <?php esc_html_e( 'Open in new tab', 'formidable' ); ?>
116 + </label>
117 + </div>
118 + <?php
94 119 }
95 120
96 121 /**
97 122 * Shows page settings.
@@ -104,19 +129,13 @@
104 129 * @type object $form Form data.
105 130 * @type string $action_key Action key.
106 131 * @type array $values Contains `fields` (form fields) and `id` (form ID).
107 132 * }
108 - *
109 - * @return void
110 133 */
111 134 public static function show_page_settings( $args ) {
112 135 $name_attr = $args['action_control']->get_field_name( 'success_page_id' );
113 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
114 136 ?>
115 - <div class="frm_form_field frm-mt-xs">
116 - <div class="frm_note_style frm-mt-0 frm-mb-md">
117 - <?php esc_html_e( 'NOTE: The selected page content will be displayed, but the full page will not be loaded. Traditional URL tracking in Google Analytics and similar tools won\'t register a page load event. If precise tracking is essential, consider using the \'Redirect to URL\' option.', 'formidable' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong ?>
118 - </div>
137 + <div class="frm_form_field">
119 138 <label for="<?php echo esc_attr( $name_attr ); ?>" class="screen-reader-text">
120 139 <?php esc_html_e( 'Select a page', 'formidable' ); ?>
121 140 </label>
122 141 <?php
@@ -129,9 +148,8 @@
129 148 );
130 149 ?>
131 150 </div>
132 151 <?php
133 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
134 152 }
135 153
136 154 /**
137 155 * Gets all active On Submit form actions for form.
@@ -139,15 +157,13 @@
139 157 * action is created during run time. If you use another cache method, please remember to delete the cache in
140 158 * {@see FrmFormAction::save_settings()}.
141 159 *
142 160 * @param int $form_id Form ID.
143 - *
144 161 * @return array
145 162 */
146 163 public static function get_actions( $form_id ) {
147 164 $cache_key = 'frm_on_submit_actions_' . $form_id;
148 165 $actions = wp_cache_get( $cache_key, 'frm_actions' );
149 -
150 166 if ( false !== $actions ) {
151 167 return $actions;
152 168 }
153 169
@@ -159,33 +175,26 @@
159 175 /**
160 176 * Gets On Submit action type (message, redirect or page).
161 177 *
162 178 * @param object $action Form action object.
163 - *
164 179 * @return string
165 180 */
166 181 public static function get_action_type( $action ) {
167 - return $action->post_content['success_action'] ?? self::get_default_action_type();
182 + if ( isset( $action->post_content['success_action'] ) ) {
183 + return $action->post_content['success_action'];
184 + }
185 + return self::get_default_action_type();
168 186 }
169 187
170 - /**
171 - * @return string
172 - */
173 188 public static function get_default_action_type() {
174 189 return 'message';
175 190 }
176 191
177 - /**
178 - * @return string
179 - */
180 192 public static function get_default_msg() {
181 193 $msg = FrmAppHelper::get_settings()->success_msg;
182 194 return $msg ? $msg : __( 'Your responses were successfully submitted. Thank you!', 'formidable' );
183 195 }
184 196
185 - /**
186 - * @return string
187 - */
188 197 public static function get_default_redirect_msg() {
189 198 return __( 'Please wait while you are redirected.', 'formidable' );
190 199 }
191 200
@@ -203,21 +212,17 @@
203 212 /**
204 213 * Adds the first On Submit action data to the form options to be saved.
205 214 *
206 215 * @param int $form_id Form ID.
207 - *
208 - * @return void
209 216 */
210 217 public static function save_on_submit_settings( $form_id ) {
211 218 $actions = self::get_actions( $form_id );
212 219 $first_create_action = null;
213 220 $first_edit_action = null;
214 -
215 221 foreach ( $actions as $action ) {
216 222 if ( ! $first_create_action && in_array( 'create', $action->post_content['event'], true ) ) {
217 223 $first_create_action = $action;
218 224 }
219 -
220 225 if ( ! $first_edit_action && in_array( 'update', $action->post_content['event'], true ) ) {
221 226 $first_edit_action = $action;
222 227 }
223 228 }
@@ -223,18 +228,16 @@
223 228 }
224 229
225 230 $form_options = array();
226 231 self::populate_on_submit_data( $form_options, $first_create_action );
227 -
228 232 if ( method_exists( 'FrmProFormActionsController', 'change_on_submit_action_ops' ) && FrmAppHelper::pro_is_connected() ) {
229 233 $form_editable = FrmDb::get_var( 'frm_forms', array( 'id' => $form_id ), 'editable' );
230 -
231 234 if ( $form_editable ) {
232 235 self::populate_on_submit_data( $form_options, $first_edit_action, 'update' );
233 236 }
234 237 }
235 238
236 - if ( $form_options ) {
239 + if ( ! empty( $form_options ) ) {
237 240 $_POST['options'] += $form_options;
238 241 }
239 242 }
240 243
@@ -240,17 +243,14 @@
240 243
241 244 /**
242 245 * Populates the On Submit data to form options.
243 246 *
244 - * @param array $form_options Form options.
245 - * @param object|null $action Optional. The On Submit action object.
246 - * @param string $event Form event. Default is `create`.
247 - *
248 - * @return void
247 + * @param array $form_options Form options.
248 + * @param object $action Optional. The On Submit action object.
249 + * @param string $event Form event. Default is `create`.
249 250 */
250 251 public static function populate_on_submit_data( &$form_options, $action = null, $event = 'create' ) {
251 252 $opt = 'update' === $event ? 'edit_' : 'success_';
252 -
253 253 if ( ! $action || ! is_object( $action ) ) {
254 254 $form_options[ $opt . 'action' ] = self::get_default_action_type();
255 255 $form_options[ $opt . 'msg' ] = self::get_default_msg();
256 256
@@ -256,21 +256,18 @@
256 256
257 257 return;
258 258 }
259 259
260 - $form_options[ $opt . 'action' ] = $action->post_content['success_action'] ?? 'message';
260 + $form_options[ $opt . 'action' ] = isset( $action->post_content['success_action'] ) ? $action->post_content['success_action'] : 'message';
261 261
262 262 switch ( $form_options[ $opt . 'action' ] ) {
263 263 case 'redirect':
264 - $form_options[ $opt . 'url' ] = $action->post_content['success_url'] ?? '';
265 - $form_options['open_in_new_tab'] = ! empty( $action->post_content['open_in_new_tab'] );
266 - $form_options['redirect_delay'] = ! empty( $action->post_content['redirect_delay'] );
267 - $form_options['redirect_delay_time'] = $action->post_content['redirect_delay_time'];
268 - $form_options['redirect_delay_msg'] = $action->post_content['redirect_delay_msg'];
264 + $form_options[ $opt . 'url' ] = isset( $action->post_content['success_url'] ) ? $action->post_content['success_url'] : '';
265 + $form_options['open_in_new_tab'] = ! empty( $action->post_content['open_in_new_tab'] );
269 266 break;
270 267
271 268 case 'page':
272 - $form_options[ $opt . 'page_id' ] = $action->post_content['success_page_id'] ?? '';
269 + $form_options[ $opt . 'page_id' ] = isset( $action->post_content['success_page_id'] ) ? $action->post_content['success_page_id'] : '';
273 270 break;
274 271
275 272 default:
276 273 $form_options[ $opt . 'msg' ] = ! empty( $action->post_content['success_msg'] ) ? $action->post_content['success_msg'] : self::get_default_msg();
@@ -284,14 +281,11 @@
284 281 *
285 282 * @since 6.1.1
286 283 *
287 284 * @param int $form_id Form ID.
288 - *
289 - * @return void
290 285 */
291 286 public static function maybe_migrate_submit_settings_to_action( $form_id ) {
292 287 $form = FrmDb::get_row( 'frm_forms', array( 'id' => $form_id ), 'options,editable' );
293 -
294 288 if ( ! $form ) {
295 289 return;
296 290 }
297 291
@@ -300,15 +294,14 @@
300 294 if ( self::form_has_migrated( $form ) ) {
301 295 return;
302 296 }
303 297
304 - $form->id = $form_id;
298 + $form->id = $form_id;
305 299 $action_type = FrmOnSubmitAction::$slug;
306 300
307 301 // Check if form already has form actions to avoid creating duplicates.
308 302 $has_actions = FrmFormAction::form_has_action_type( $form_id, $action_type );
309 -
310 - if ( $has_actions ) {
303 + if ( ! empty( $has_actions ) ) {
311 304 // Don't migrate again.
312 305 self::save_migrated_success_actions( $form );
313 306 return;
314 307 }
@@ -360,28 +353,27 @@
360 353 * @since 6.1.1
361 354 *
362 355 * @param array $form_options Form options.
363 356 * @param string $event Action event. Accepts `create` or `update`. Default is `create`.
364 - *
365 357 * @return array
366 358 */
367 359 private static function get_on_submit_action_data_from_form_options( $form_options, $event = 'create' ) {
368 360 $opt = 'update' === $event ? 'edit_' : 'success_';
369 361 $data = array(
370 - 'success_action' => $form_options[ $opt . 'action' ] ?? self::get_default_action_type(),
362 + 'success_action' => isset( $form_options[ $opt . 'action' ] ) ? $form_options[ $opt . 'action' ] : self::get_default_action_type(),
371 363 );
372 364
373 365 switch ( $data['success_action'] ) {
374 366 case 'redirect':
375 - $data['success_url'] = $form_options[ $opt . 'url' ] ?? '';
367 + $data['success_url'] = isset( $form_options[ $opt . 'url' ] ) ? $form_options[ $opt . 'url' ] : '';
376 368 break;
377 369
378 370 case 'page':
379 - $data['success_page_id'] = $form_options[ $opt . 'page_id' ] ?? '';
371 + $data['success_page_id'] = isset( $form_options[ $opt . 'page_id' ] ) ? $form_options[ $opt . 'page_id' ] : '';
380 372 break;
381 373
382 374 default:
383 - $data['success_msg'] = $form_options[ $opt . 'msg' ] ?? self::get_default_msg();
375 + $data['success_msg'] = isset( $form_options[ $opt . 'msg' ] ) ? $form_options[ $opt . 'msg' ] : self::get_default_msg();
384 376 $data['show_form'] = ! empty( $form_options['show_form'] );
385 377 }
386 378
387 379 return $data;
@@ -392,9 +384,8 @@
392 384 *
393 385 * @since 6.1.1
394 386 *
395 387 * @param object $form Form object.
396 - *
397 388 * @return bool
398 389 */
399 390 public static function form_has_migrated( $form ) {
400 391 return ! empty( $form->options['on_submit_migrated'] );
@@ -403,16 +394,10 @@
403 394 /**
404 395 * @since 6.1.1
405 396 *
406 397 * @param object $form Limited form object.
407 - *
408 - * @return void
409 398 */
410 399 private static function save_migrated_success_actions( $form ) {
411 - // Options may be an empty string.
412 - if ( ! is_array( $form->options ) ) {
413 - $form->options = array();
414 - }
415 400 $form->options['on_submit_migrated'] = 1;
416 401 FrmForm::update( $form->id, array( 'options' => $form->options ) );
417 402 }
418 403
@@ -420,27 +405,19 @@
420 405 * Gets fallback action, used when no actions match.
421 406 *
422 407 * @since 6.1.1
423 408 *
424 - * @param array|string $event Uses 'create' or 'update'.
409 + * @param string|array $event Uses 'create' or 'update'.
425 410 *
426 411 * @return object
427 412 */
428 413 public static function get_fallback_action( $event = 'create' ) {
429 - $action = new stdClass();
430 - $default_msg = self::get_default_msg();
414 + $action = new stdClass();
431 415
432 - if ( current_user_can( 'frm_edit_forms' ) ) {
433 - $default_msg .= '<br />';
434 - $default_msg .= '<span style="font-weight: 600; font-style: italic;">';
435 - $default_msg .= __( 'This is the fallback message. No confirmation actions match your conditional logic, or they are invalid.', 'formidable' );
436 - $default_msg .= '</span>';
437 - }
438 -
439 416 $action->post_content = array(
440 417 'event' => (array) $event,
441 418 'success_action' => 'message',
442 - 'success_msg' => $default_msg,
419 + 'success_msg' => self::get_default_msg(),
443 420 );
444 421
445 422 return $action;
446 423 }
@@ -449,10 +426,9 @@
449 426 * Gets fallback action after opening the redirect URL in a new tab.
450 427 *
451 428 * @since 6.3.1
452 429 *
453 - * @param array|string $event Uses 'create' or 'update'.
454 - *
430 + * @param string|array $event Uses 'create' or 'update'.
455 431 * @return object
456 432 */
457 433 public static function get_fallback_action_after_open_in_new_tab( $event ) {
458 434 $action = self::get_fallback_action( $event );
@@ -462,13 +438,11 @@
462 438 return $action;
463 439 }
464 440
465 441 /**
466 - * Check if the current event has been passed. If not, use create actions.
442 + * Check if the current event has been paased. If not, use create actions.
467 443 *
468 444 * @since 6.1.1
469 - *
470 - * @param array $atts
471 445 *
472 446 * @return string
473 447 */
474 448 public static function current_event( $atts ) {