PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.2.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.2.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 +36 -111 6.32.16.2.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,22 @@
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 + <?php
94 98 }
95 99
96 100 /**
97 101 * Shows page settings.
@@ -104,19 +108,13 @@
104 108 * @type object $form Form data.
105 109 * @type string $action_key Action key.
106 110 * @type array $values Contains `fields` (form fields) and `id` (form ID).
107 111 * }
108 - *
109 - * @return void
110 112 */
111 113 public static function show_page_settings( $args ) {
112 114 $name_attr = $args['action_control']->get_field_name( 'success_page_id' );
113 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
114 115 ?>
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>
116 + <div class="frm_form_field">
119 117 <label for="<?php echo esc_attr( $name_attr ); ?>" class="screen-reader-text">
120 118 <?php esc_html_e( 'Select a page', 'formidable' ); ?>
121 119 </label>
122 120 <?php
@@ -129,9 +127,8 @@
129 127 );
130 128 ?>
131 129 </div>
132 130 <?php
133 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
134 131 }
135 132
136 133 /**
137 134 * Gets all active On Submit form actions for form.
@@ -139,15 +136,13 @@
139 136 * action is created during run time. If you use another cache method, please remember to delete the cache in
140 137 * {@see FrmFormAction::save_settings()}.
141 138 *
142 139 * @param int $form_id Form ID.
143 - *
144 140 * @return array
145 141 */
146 142 public static function get_actions( $form_id ) {
147 143 $cache_key = 'frm_on_submit_actions_' . $form_id;
148 144 $actions = wp_cache_get( $cache_key, 'frm_actions' );
149 -
150 145 if ( false !== $actions ) {
151 146 return $actions;
152 147 }
153 148
@@ -159,65 +154,43 @@
159 154 /**
160 155 * Gets On Submit action type (message, redirect or page).
161 156 *
162 157 * @param object $action Form action object.
163 - *
164 158 * @return string
165 159 */
166 160 public static function get_action_type( $action ) {
167 - return $action->post_content['success_action'] ?? self::get_default_action_type();
161 + if ( isset( $action->post_content['success_action'] ) ) {
162 + return $action->post_content['success_action'];
163 + }
164 + return self::get_default_action_type();
168 165 }
169 166
170 - /**
171 - * @return string
172 - */
173 167 public static function get_default_action_type() {
174 168 return 'message';
175 169 }
176 170
177 - /**
178 - * @return string
179 - */
180 171 public static function get_default_msg() {
181 172 $msg = FrmAppHelper::get_settings()->success_msg;
182 173 return $msg ? $msg : __( 'Your responses were successfully submitted. Thank you!', 'formidable' );
183 174 }
184 175
185 - /**
186 - * @return string
187 - */
188 176 public static function get_default_redirect_msg() {
189 177 return __( 'Please wait while you are redirected.', 'formidable' );
190 178 }
191 179
192 180 /**
193 - * Gets the default open in new tab message.
194 - *
195 - * @since 6.3.1
196 - *
197 - * @return string
198 - */
199 - public static function get_default_new_tab_msg() {
200 - return FrmAppHelper::get_settings()->new_tab_msg;
201 - }
202 -
203 - /**
204 181 * Adds the first On Submit action data to the form options to be saved.
205 182 *
206 183 * @param int $form_id Form ID.
207 - *
208 - * @return void
209 184 */
210 185 public static function save_on_submit_settings( $form_id ) {
211 186 $actions = self::get_actions( $form_id );
212 187 $first_create_action = null;
213 188 $first_edit_action = null;
214 -
215 189 foreach ( $actions as $action ) {
216 190 if ( ! $first_create_action && in_array( 'create', $action->post_content['event'], true ) ) {
217 191 $first_create_action = $action;
218 192 }
219 -
220 193 if ( ! $first_edit_action && in_array( 'update', $action->post_content['event'], true ) ) {
221 194 $first_edit_action = $action;
222 195 }
223 196 }
@@ -223,18 +196,16 @@
223 196 }
224 197
225 198 $form_options = array();
226 199 self::populate_on_submit_data( $form_options, $first_create_action );
227 -
228 200 if ( method_exists( 'FrmProFormActionsController', 'change_on_submit_action_ops' ) && FrmAppHelper::pro_is_connected() ) {
229 201 $form_editable = FrmDb::get_var( 'frm_forms', array( 'id' => $form_id ), 'editable' );
230 -
231 202 if ( $form_editable ) {
232 203 self::populate_on_submit_data( $form_options, $first_edit_action, 'update' );
233 204 }
234 205 }
235 206
236 - if ( $form_options ) {
207 + if ( ! empty( $form_options ) ) {
237 208 $_POST['options'] += $form_options;
238 209 }
239 210 }
240 211
@@ -240,17 +211,14 @@
240 211
241 212 /**
242 213 * Populates the On Submit data to form options.
243 214 *
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
215 + * @param array $form_options Form options.
216 + * @param object $action Optional. The On Submit action object.
217 + * @param string $event Form event. Default is `create`.
249 218 */
250 219 public static function populate_on_submit_data( &$form_options, $action = null, $event = 'create' ) {
251 220 $opt = 'update' === $event ? 'edit_' : 'success_';
252 -
253 221 if ( ! $action || ! is_object( $action ) ) {
254 222 $form_options[ $opt . 'action' ] = self::get_default_action_type();
255 223 $form_options[ $opt . 'msg' ] = self::get_default_msg();
256 224
@@ -256,21 +224,17 @@
256 224
257 225 return;
258 226 }
259 227
260 - $form_options[ $opt . 'action' ] = $action->post_content['success_action'] ?? 'message';
228 + $form_options[ $opt . 'action' ] = isset( $action->post_content['success_action'] ) ? $action->post_content['success_action'] : 'message';
261 229
262 230 switch ( $form_options[ $opt . 'action' ] ) {
263 231 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'];
232 + $form_options[ $opt . 'url' ] = isset( $action->post_content['success_url'] ) ? $action->post_content['success_url'] : '';
269 233 break;
270 234
271 235 case 'page':
272 - $form_options[ $opt . 'page_id' ] = $action->post_content['success_page_id'] ?? '';
236 + $form_options[ $opt . 'page_id' ] = isset( $action->post_content['success_page_id'] ) ? $action->post_content['success_page_id'] : '';
273 237 break;
274 238
275 239 default:
276 240 $form_options[ $opt . 'msg' ] = ! empty( $action->post_content['success_msg'] ) ? $action->post_content['success_msg'] : self::get_default_msg();
@@ -284,14 +248,11 @@
284 248 *
285 249 * @since 6.1.1
286 250 *
287 251 * @param int $form_id Form ID.
288 - *
289 - * @return void
290 252 */
291 253 public static function maybe_migrate_submit_settings_to_action( $form_id ) {
292 254 $form = FrmDb::get_row( 'frm_forms', array( 'id' => $form_id ), 'options,editable' );
293 -
294 255 if ( ! $form ) {
295 256 return;
296 257 }
297 258
@@ -300,15 +261,14 @@
300 261 if ( self::form_has_migrated( $form ) ) {
301 262 return;
302 263 }
303 264
304 - $form->id = $form_id;
265 + $form->id = $form_id;
305 266 $action_type = FrmOnSubmitAction::$slug;
306 267
307 268 // Check if form already has form actions to avoid creating duplicates.
308 269 $has_actions = FrmFormAction::form_has_action_type( $form_id, $action_type );
309 -
310 - if ( $has_actions ) {
270 + if ( ! empty( $has_actions ) ) {
311 271 // Don't migrate again.
312 272 self::save_migrated_success_actions( $form );
313 273 return;
314 274 }
@@ -360,28 +320,27 @@
360 320 * @since 6.1.1
361 321 *
362 322 * @param array $form_options Form options.
363 323 * @param string $event Action event. Accepts `create` or `update`. Default is `create`.
364 - *
365 324 * @return array
366 325 */
367 326 private static function get_on_submit_action_data_from_form_options( $form_options, $event = 'create' ) {
368 327 $opt = 'update' === $event ? 'edit_' : 'success_';
369 328 $data = array(
370 - 'success_action' => $form_options[ $opt . 'action' ] ?? self::get_default_action_type(),
329 + 'success_action' => isset( $form_options[ $opt . 'action' ] ) ? $form_options[ $opt . 'action' ] : self::get_default_action_type(),
371 330 );
372 331
373 332 switch ( $data['success_action'] ) {
374 333 case 'redirect':
375 - $data['success_url'] = $form_options[ $opt . 'url' ] ?? '';
334 + $data['success_url'] = isset( $form_options[ $opt . 'url' ] ) ? $form_options[ $opt . 'url' ] : '';
376 335 break;
377 336
378 337 case 'page':
379 - $data['success_page_id'] = $form_options[ $opt . 'page_id' ] ?? '';
338 + $data['success_page_id'] = isset( $form_options[ $opt . 'page_id' ] ) ? $form_options[ $opt . 'page_id' ] : '';
380 339 break;
381 340
382 341 default:
383 - $data['success_msg'] = $form_options[ $opt . 'msg' ] ?? self::get_default_msg();
342 + $data['success_msg'] = isset( $form_options[ $opt . 'msg' ] ) ? $form_options[ $opt . 'msg' ] : self::get_default_msg();
384 343 $data['show_form'] = ! empty( $form_options['show_form'] );
385 344 }
386 345
387 346 return $data;
@@ -392,9 +351,8 @@
392 351 *
393 352 * @since 6.1.1
394 353 *
395 354 * @param object $form Form object.
396 - *
397 355 * @return bool
398 356 */
399 357 public static function form_has_migrated( $form ) {
400 358 return ! empty( $form->options['on_submit_migrated'] );
@@ -403,16 +361,10 @@
403 361 /**
404 362 * @since 6.1.1
405 363 *
406 364 * @param object $form Limited form object.
407 - *
408 - * @return void
409 365 */
410 366 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 367 $form->options['on_submit_migrated'] = 1;
416 368 FrmForm::update( $form->id, array( 'options' => $form->options ) );
417 369 }
418 370
@@ -420,27 +372,19 @@
420 372 * Gets fallback action, used when no actions match.
421 373 *
422 374 * @since 6.1.1
423 375 *
424 - * @param array|string $event Uses 'create' or 'update'.
376 + * @param string|array $event Uses 'create' or 'update'.
425 377 *
426 378 * @return object
427 379 */
428 380 public static function get_fallback_action( $event = 'create' ) {
429 - $action = new stdClass();
430 - $default_msg = self::get_default_msg();
381 + $action = new stdClass();
431 382
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 383 $action->post_content = array(
440 384 'event' => (array) $event,
441 385 'success_action' => 'message',
442 - 'success_msg' => $default_msg,
386 + 'success_msg' => self::get_default_msg(),
443 387 );
444 388
445 389 return $action;
446 390 }
@@ -445,30 +389,11 @@
445 389 return $action;
446 390 }
447 391
448 392 /**
449 - * Gets fallback action after opening the redirect URL in a new tab.
393 + * Check if the current event has been paased. If not, use create actions.
450 394 *
451 - * @since 6.3.1
452 - *
453 - * @param array|string $event Uses 'create' or 'update'.
454 - *
455 - * @return object
456 - */
457 - public static function get_fallback_action_after_open_in_new_tab( $event ) {
458 - $action = self::get_fallback_action( $event );
459 -
460 - $action->post_content['success_msg'] = self::get_default_new_tab_msg();
461 -
462 - return $action;
463 - }
464 -
465 - /**
466 - * Check if the current event has been passed. If not, use create actions.
467 - *
468 395 * @since 6.1.1
469 - *
470 - * @param array $atts
471 396 *
472 397 * @return string
473 398 */
474 399 public static function current_event( $atts ) {