PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.13
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.13
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 +47 -65 6.26.1 → 6.13 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,10 +23,8 @@
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 30 ?>
@@ -83,13 +80,43 @@
83 80 * @type object $form Form data.
84 81 * @type string $action_key Action key.
85 82 * @type array $values Contains `fields` (form fields) and `id` (form ID).
86 83 * }
87 - *
88 - * @return void
89 84 */
90 85 public static function show_redirect_settings( $args ) {
91 - 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
92 119 }
93 120
94 121 /**
95 122 * Shows page settings.
@@ -102,18 +129,13 @@
102 129 * @type object $form Form data.
103 130 * @type string $action_key Action key.
104 131 * @type array $values Contains `fields` (form fields) and `id` (form ID).
105 132 * }
106 - *
107 - * @return void
108 133 */
109 134 public static function show_page_settings( $args ) {
110 135 $name_attr = $args['action_control']->get_field_name( 'success_page_id' );
111 136 ?>
112 137 <div class="frm_form_field">
113 - <div class="frm_note_style">
114 - <?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 ?>
115 - </div>
116 138 <label for="<?php echo esc_attr( $name_attr ); ?>" class="screen-reader-text">
117 139 <?php esc_html_e( 'Select a page', 'formidable' ); ?>
118 140 </label>
119 141 <?php
@@ -135,15 +157,13 @@
135 157 * action is created during run time. If you use another cache method, please remember to delete the cache in
136 158 * {@see FrmFormAction::save_settings()}.
137 159 *
138 160 * @param int $form_id Form ID.
139 - *
140 161 * @return array
141 162 */
142 163 public static function get_actions( $form_id ) {
143 164 $cache_key = 'frm_on_submit_actions_' . $form_id;
144 165 $actions = wp_cache_get( $cache_key, 'frm_actions' );
145 -
146 166 if ( false !== $actions ) {
147 167 return $actions;
148 168 }
149 169
@@ -155,33 +175,26 @@
155 175 /**
156 176 * Gets On Submit action type (message, redirect or page).
157 177 *
158 178 * @param object $action Form action object.
159 - *
160 179 * @return string
161 180 */
162 181 public static function get_action_type( $action ) {
163 - 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();
164 186 }
165 187
166 - /**
167 - * @return string
168 - */
169 188 public static function get_default_action_type() {
170 189 return 'message';
171 190 }
172 191
173 - /**
174 - * @return string
175 - */
176 192 public static function get_default_msg() {
177 193 $msg = FrmAppHelper::get_settings()->success_msg;
178 194 return $msg ? $msg : __( 'Your responses were successfully submitted. Thank you!', 'formidable' );
179 195 }
180 196
181 - /**
182 - * @return string
183 - */
184 197 public static function get_default_redirect_msg() {
185 198 return __( 'Please wait while you are redirected.', 'formidable' );
186 199 }
187 200
@@ -199,21 +212,17 @@
199 212 /**
200 213 * Adds the first On Submit action data to the form options to be saved.
201 214 *
202 215 * @param int $form_id Form ID.
203 - *
204 - * @return void
205 216 */
206 217 public static function save_on_submit_settings( $form_id ) {
207 218 $actions = self::get_actions( $form_id );
208 219 $first_create_action = null;
209 220 $first_edit_action = null;
210 -
211 221 foreach ( $actions as $action ) {
212 222 if ( ! $first_create_action && in_array( 'create', $action->post_content['event'], true ) ) {
213 223 $first_create_action = $action;
214 224 }
215 -
216 225 if ( ! $first_edit_action && in_array( 'update', $action->post_content['event'], true ) ) {
217 226 $first_edit_action = $action;
218 227 }
219 228 }
@@ -219,12 +228,10 @@
219 228 }
220 229
221 230 $form_options = array();
222 231 self::populate_on_submit_data( $form_options, $first_create_action );
223 -
224 232 if ( method_exists( 'FrmProFormActionsController', 'change_on_submit_action_ops' ) && FrmAppHelper::pro_is_connected() ) {
225 233 $form_editable = FrmDb::get_var( 'frm_forms', array( 'id' => $form_id ), 'editable' );
226 -
227 234 if ( $form_editable ) {
228 235 self::populate_on_submit_data( $form_options, $first_edit_action, 'update' );
229 236 }
230 237 }
@@ -239,14 +246,11 @@
239 246 *
240 247 * @param array $form_options Form options.
241 248 * @param object $action Optional. The On Submit action object.
242 249 * @param string $event Form event. Default is `create`.
243 - *
244 - * @return void
245 250 */
246 251 public static function populate_on_submit_data( &$form_options, $action = null, $event = 'create' ) {
247 252 $opt = 'update' === $event ? 'edit_' : 'success_';
248 -
249 253 if ( ! $action || ! is_object( $action ) ) {
250 254 $form_options[ $opt . 'action' ] = self::get_default_action_type();
251 255 $form_options[ $opt . 'msg' ] = self::get_default_msg();
252 256
@@ -252,21 +256,18 @@
252 256
253 257 return;
254 258 }
255 259
256 - $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';
257 261
258 262 switch ( $form_options[ $opt . 'action' ] ) {
259 263 case 'redirect':
260 - $form_options[ $opt . 'url' ] = $action->post_content['success_url'] ?? '';
261 - $form_options['open_in_new_tab'] = ! empty( $action->post_content['open_in_new_tab'] );
262 - $form_options['redirect_delay'] = ! empty( $action->post_content['redirect_delay'] );
263 - $form_options['redirect_delay_time'] = $action->post_content['redirect_delay_time'];
264 - $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'] );
265 266 break;
266 267
267 268 case 'page':
268 - $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'] : '';
269 270 break;
270 271
271 272 default:
272 273 $form_options[ $opt . 'msg' ] = ! empty( $action->post_content['success_msg'] ) ? $action->post_content['success_msg'] : self::get_default_msg();
@@ -280,14 +281,11 @@
280 281 *
281 282 * @since 6.1.1
282 283 *
283 284 * @param int $form_id Form ID.
284 - *
285 - * @return void
286 285 */
287 286 public static function maybe_migrate_submit_settings_to_action( $form_id ) {
288 287 $form = FrmDb::get_row( 'frm_forms', array( 'id' => $form_id ), 'options,editable' );
289 -
290 288 if ( ! $form ) {
291 289 return;
292 290 }
293 291
@@ -301,9 +299,8 @@
301 299 $action_type = FrmOnSubmitAction::$slug;
302 300
303 301 // Check if form already has form actions to avoid creating duplicates.
304 302 $has_actions = FrmFormAction::form_has_action_type( $form_id, $action_type );
305 -
306 303 if ( ! empty( $has_actions ) ) {
307 304 // Don't migrate again.
308 305 self::save_migrated_success_actions( $form );
309 306 return;
@@ -356,28 +353,27 @@
356 353 * @since 6.1.1
357 354 *
358 355 * @param array $form_options Form options.
359 356 * @param string $event Action event. Accepts `create` or `update`. Default is `create`.
360 - *
361 357 * @return array
362 358 */
363 359 private static function get_on_submit_action_data_from_form_options( $form_options, $event = 'create' ) {
364 360 $opt = 'update' === $event ? 'edit_' : 'success_';
365 361 $data = array(
366 - '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(),
367 363 );
368 364
369 365 switch ( $data['success_action'] ) {
370 366 case 'redirect':
371 - $data['success_url'] = $form_options[ $opt . 'url' ] ?? '';
367 + $data['success_url'] = isset( $form_options[ $opt . 'url' ] ) ? $form_options[ $opt . 'url' ] : '';
372 368 break;
373 369
374 370 case 'page':
375 - $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' ] : '';
376 372 break;
377 373
378 374 default:
379 - $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();
380 376 $data['show_form'] = ! empty( $form_options['show_form'] );
381 377 }
382 378
383 379 return $data;
@@ -388,9 +384,8 @@
388 384 *
389 385 * @since 6.1.1
390 386 *
391 387 * @param object $form Form object.
392 - *
393 388 * @return bool
394 389 */
395 390 public static function form_has_migrated( $form ) {
396 391 return ! empty( $form->options['on_submit_migrated'] );
@@ -399,9 +394,8 @@
399 394 /**
400 395 * @since 6.1.1
401 396 *
402 397 * @param object $form Limited form object.
403 - *
404 398 * @return void
405 399 */
406 400 private static function save_migrated_success_actions( $form ) {
407 401 // Options may be an empty string.
@@ -423,21 +417,12 @@
423 417 */
424 418 public static function get_fallback_action( $event = 'create' ) {
425 419 $action = new stdClass();
426 420
427 - $default_msg = self::get_default_msg();
428 -
429 - if ( current_user_can( 'frm_edit_forms' ) ) {
430 - $default_msg .= '<br />';
431 - $default_msg .= '<span style="font-weight: 600; font-style: italic;">';
432 - $default_msg .= __( 'This is the fallback message. No confirmation actions match your conditional logic, or they are invalid.', 'formidable' );
433 - $default_msg .= '</span>';
434 - }
435 -
436 421 $action->post_content = array(
437 422 'event' => (array) $event,
438 423 'success_action' => 'message',
439 - 'success_msg' => $default_msg,
424 + 'success_msg' => self::get_default_msg(),
440 425 );
441 426
442 427 return $action;
443 428 }
@@ -447,9 +432,8 @@
447 432 *
448 433 * @since 6.3.1
449 434 *
450 435 * @param array|string $event Uses 'create' or 'update'.
451 - *
452 436 * @return object
453 437 */
454 438 public static function get_fallback_action_after_open_in_new_tab( $event ) {
455 439 $action = self::get_fallback_action( $event );
@@ -459,13 +443,11 @@
459 443 return $action;
460 444 }
461 445
462 446 /**
463 - * Check if the current event has been passed. If not, use create actions.
447 + * Check if the current event has been paased. If not, use create actions.
464 448 *
465 449 * @since 6.1.1
466 - *
467 - * @param array $atts
468 450 *
469 451 * @return string
470 452 */
471 453 public static function current_event( $atts ) {