PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.2
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.2
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/controllers/FrmFormsController.php +52 -144 6.5.26.2 View file →
@@ -5,16 +5,15 @@
5 5
6 6 class FrmFormsController {
7 7
8 8 /**
9 - * Track the form that opened the redirect URL in a new tab. This is used to check if we should show the default
10 - * message in the currect tab.
9 + * Track the form and action that ran frm_redirect_url filter. Each item in array is {form_id}_create or {form_id}_update.
11 10 *
12 11 * @since 6.2
13 12 *
14 - * @var array Keys are form IDs and values are 1.
13 + * @var array
15 14 */
16 - private static $redirected_in_new_tab = array();
15 + private static $ran_redirect_url_filter = array();
17 16
18 17 public static function menu() {
19 18 $menu_label = __( 'Forms', 'formidable' );
20 19 if ( ! FrmAppHelper::pro_is_installed() ) {
@@ -889,14 +888,14 @@
889 888 * @return array<string,string>
890 889 */
891 890 public static function get_columns( $columns ) {
892 891 $columns['cb'] = '<input type="checkbox" />';
893 - $columns['name'] = esc_html__( 'Form Title', 'formidable' );
894 - $columns['entries'] = esc_html__( 'Entries', 'formidable' );
892 + $columns['name'] = __( 'Form Title', 'formidable' );
893 + $columns['entries'] = __( 'Entries', 'formidable' );
895 894 $columns['id'] = 'ID';
896 - $columns['form_key'] = esc_html__( 'Key', 'formidable' );
897 - $columns['shortcode'] = esc_html__( 'Actions', 'formidable' );
898 - $columns['created_at'] = esc_html__( 'Date', 'formidable' );
895 + $columns['form_key'] = __( 'Key', 'formidable' );
896 + $columns['shortcode'] = __( 'Actions', 'formidable' );
897 + $columns['created_at'] = __( 'Date', 'formidable' );
899 898
900 899 add_screen_option(
901 900 'per_page',
902 901 array(
@@ -1269,21 +1268,8 @@
1269 1268 'screenshot' => 'chat.png',
1270 1269 )
1271 1270 ),
1272 1271 ),
1273 - 'abandonment' => array(
1274 - 'name' => __( 'Form Abandonment', 'formidable' ),
1275 - 'icon' => 'frm_icon_font frm_abandoned_icon',
1276 - 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1277 - 'data' => FrmAppHelper::get_upgrade_data_params(
1278 - 'abandonment',
1279 - array(
1280 - 'upgrade' => __( 'Form abandonment settings', 'formidable' ),
1281 - 'message' => __( 'Unlock the power of data capture to boost lead generation and master the art of form optimization.', 'formidable' ),
1282 - 'screenshot' => 'abandonment.png',
1283 - )
1284 - ),
1285 - ),
1286 1272 'html' => array(
1287 1273 'name' => __( 'Customize HTML', 'formidable' ),
1288 1274 'class' => __CLASS__,
1289 1275 'function' => 'html_settings',
@@ -1290,9 +1276,9 @@
1290 1276 'icon' => 'frm_icon_font frm_code_icon',
1291 1277 ),
1292 1278 );
1293 1279
1294 - foreach ( array( 'landing', 'chat', 'abandonment' ) as $feature ) {
1280 + foreach ( array( 'landing', 'chat' ) as $feature ) {
1295 1281 if ( ! FrmAppHelper::show_new_feature( $feature ) ) {
1296 1282 unset( $sections[ $feature ] );
1297 1283 }
1298 1284 }
@@ -1628,17 +1614,13 @@
1628 1614 * Replace any [form_name] shortcodes in a string.
1629 1615 *
1630 1616 * @since 5.5
1631 1617 *
1632 - * @param string|array $string
1618 + * @param string $string
1633 1619 * @param stdClass|string|int $form
1634 - * @return string|array
1620 + * @return string
1635 1621 */
1636 1622 public static function replace_form_name_shortcodes( $string, $form ) {
1637 - if ( ! is_string( $string ) ) {
1638 - return $string;
1639 - }
1640 -
1641 1623 if ( false === strpos( $string, '[form_name]' ) ) {
1642 1624 return $string;
1643 1625 }
1644 1626
@@ -2288,13 +2270,8 @@
2288 2270 if ( ! FrmOnSubmitHelper::form_has_migrated( $args['form'] ) ) {
2289 2271 return array();
2290 2272 }
2291 2273
2292 - // If a redirect action has already opened the URL in a new tab, we show the default message in the currect tab.
2293 - if ( ! empty( self::$redirected_in_new_tab[ $args['form']->id ] ) ) {
2294 - return array( FrmOnSubmitHelper::get_fallback_action_after_open_in_new_tab( $event ) );
2295 - }
2296 -
2297 2274 $entry = FrmEntry::getOne( $args['entry_id'], true );
2298 2275 $actions = FrmOnSubmitHelper::get_actions( $args['form']->id );
2299 2276 $met_actions = array();
2300 2277 $has_redirect = false;
@@ -2313,11 +2290,18 @@
2313 2290 if ( 'redirect' === $action_type ) {
2314 2291 if ( $has_redirect ) { // Do not process because we run the first redirect action only.
2315 2292 continue;
2316 2293 }
2294 +
2295 + // Run through frm_redirect_url filter. This is used for the valid action check.
2296 + $action->post_content['success_url'] = self::run_redirect_url_filter(
2297 + $action->post_content['success_url'],
2298 + $args['form'],
2299 + $args + array( 'action' => $event )
2300 + );
2317 2301 }
2318 2302
2319 - if ( ! self::is_valid_on_submit_action( $action, $args, $event ) ) {
2303 + if ( ! self::is_valid_on_submit_action( $action ) ) {
2320 2304 continue;
2321 2305 }
2322 2306
2323 2307 if ( 'redirect' === $action_type ) {
@@ -2347,30 +2331,45 @@
2347 2331 return $met_actions;
2348 2332 }
2349 2333
2350 2334 /**
2335 + * Runs frm_redirect_url filter and prepare the URL.
2336 + * This ensures that filter just fires once per form and action.
2337 + *
2338 + * @since 6.2
2339 + *
2340 + * @param string $url The URL.
2341 + * @param object $form Form object.
2342 + * @param array $args Args from {@see FrmFormsController::run_success_action()}. `$args['action']` is required.
2343 + */
2344 + private static function run_redirect_url_filter( $url, $form, $args ) {
2345 + if ( empty( $args['action'] ) || ! is_string( $args['action'] ) ) {
2346 + return $url;
2347 + }
2348 +
2349 + if ( in_array( $form->id . '_' . $args['action'], self::$ran_redirect_url_filter, true ) ) {
2350 + return $url;
2351 + }
2352 +
2353 + self::$ran_redirect_url_filter[] = $form->id . '_' . $args['action'];
2354 +
2355 + add_filter( 'frm_redirect_url', 'FrmEntriesController::prepare_redirect_url' );
2356 + return apply_filters( 'frm_redirect_url', $url, $form, $args );
2357 + }
2358 +
2359 + /**
2351 2360 * Checks if a Confirmation action has the valid data.
2352 2361 *
2353 2362 * @since 6.1.2
2354 2363 *
2355 2364 * @param object $action Form action object.
2356 - * @param array $args See {@see FrmFormsController::run_success_action()}.
2357 - * @param string $event Form event. Default is `create`.
2358 2365 * @return bool
2359 2366 */
2360 - private static function is_valid_on_submit_action( $action, $args, $event = 'create' ) {
2367 + private static function is_valid_on_submit_action( $action ) {
2361 2368 $action_type = FrmOnSubmitHelper::get_action_type( $action );
2362 2369
2363 - if ( 'redirect' === $action_type ) {
2364 - // Run through frm_redirect_url filter. This is used for the valid action check.
2365 - $action->post_content['success_url'] = apply_filters(
2366 - 'frm_redirect_url',
2367 - $action->post_content['success_url'],
2368 - $args['form'],
2369 - $args + array( 'action' => $event )
2370 - );
2371 -
2372 - return ! empty( $action->post_content['success_url'] );
2370 + if ( 'redirect' === $action_type && empty( $action->post_content['success_url'] ) ) {
2371 + return false;
2373 2372 }
2374 2373
2375 2374 if ( 'page' === $action_type ) {
2376 2375 if ( empty( $action->post_content['success_page_id'] ) ) {
@@ -2534,25 +2533,18 @@
2534 2533
2535 2534 $args['id'] = $args['entry_id'];
2536 2535 FrmEntriesController::delete_entry_before_redirect( $success_url, $args['form'], $args );
2537 2536
2538 - add_filter( 'frm_redirect_url', 'FrmEntriesController::prepare_redirect_url' );
2539 - $success_url = apply_filters( 'frm_redirect_url', $success_url, $args['form'], $args );
2537 + $success_url = self::run_redirect_url_filter( $success_url, $args['form'], $args );
2540 2538
2541 2539 $doing_ajax = FrmAppHelper::doing_ajax();
2542 2540
2543 2541 if ( ! empty( $args['ajax'] ) && $doing_ajax && empty( $args['force_delay_redirect'] ) ) { // Is AJAX submit and there is just one Redirect action runs.
2544 - echo json_encode( self::get_ajax_redirect_response_data( $args + compact( 'success_url' ) ) );
2542 + echo json_encode( array( 'redirect' => $success_url ) );
2545 2543 wp_die();
2546 2544 }
2547 2545
2548 2546 if ( ! headers_sent() && empty( $args['force_delay_redirect'] ) ) { // Not AJAX submit, no headers sent, and there is just one Redirect action runs.
2549 - if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
2550 - self::print_open_in_new_tab_js_with_fallback_handler( $success_url, $args );
2551 - self::$redirected_in_new_tab[ $args['form']->id ] = 1;
2552 - return;
2553 - }
2554 -
2555 2547 wp_redirect( esc_url_raw( $success_url ) );
2556 2548 die(); // do not use wp_die or redirect fails
2557 2549 }
2558 2550
@@ -2560,63 +2552,8 @@
2560 2552 self::redirect_after_submit_using_js( $args + compact( 'success_url', 'doing_ajax' ) );
2561 2553 }
2562 2554
2563 2555 /**
2564 - * Prints open in new tab js with fallback handler.
2565 - *
2566 - * @since 6.3.1
2567 - *
2568 - * @param string $success_url Success URL.
2569 - * @param array $args See {@see FrmFormsController::redirect_after_submit()}.
2570 - */
2571 - private static function print_open_in_new_tab_js_with_fallback_handler( $success_url, $args ) {
2572 - echo '<script>var newTab = window.open("' . esc_url_raw( $success_url ) . '", "_blank");';
2573 - echo 'if ( ! newTab ) {';
2574 -
2575 - $data = array(
2576 - 'formId' => intval( $args['form']->id ),
2577 - 'message' => self::get_redirect_fallback_message( $success_url, $args ),
2578 - );
2579 - // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2580 - echo 'frmShowNewTabFallback = ' . FrmAppHelper::maybe_json_encode( $data ) . ';';
2581 - echo '}</script>';
2582 - }
2583 -
2584 - /**
2585 - * Gets response data for redirect action when AJAX submitting.
2586 - *
2587 - * @since 6.3.1
2588 - *
2589 - * @param array $args See {@see FrmFormsController::run_success_action()}.
2590 - * @return array
2591 - */
2592 - private static function get_ajax_redirect_response_data( $args ) {
2593 - $response_data = array( 'redirect' => $args['success_url'] );
2594 -
2595 - if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
2596 - $response_data['openInNewTab'] = 1;
2597 -
2598 - $args['message'] = FrmOnSubmitHelper::get_default_new_tab_msg();
2599 -
2600 - $args['form']->options['success_msg'] = $args['message'];
2601 - $args['form']->options['edit_msg'] = $args['message'];
2602 - if ( ! isset( $args['fields'] ) ) {
2603 - $args['fields'] = FrmField::get_all_for_form( $args['form']->id );
2604 - }
2605 -
2606 - $args['message'] = self::prepare_submit_message( $args['form'], $args['entry_id'], $args );
2607 -
2608 - ob_start();
2609 - self::show_lone_success_messsage( $args );
2610 - $response_data['content'] = ob_get_clean();
2611 -
2612 - $response_data['fallbackMsg'] = self::get_redirect_fallback_message( $args['success_url'], $args );
2613 - }
2614 -
2615 - return $response_data;
2616 - }
2617 -
2618 - /**
2619 2556 * Redirects after submitting using JS. This is used when showing message before redirecting.
2620 2557 *
2621 2558 * @since 6.0
2622 2559 *
@@ -2624,9 +2561,8 @@
2624 2561 */
2625 2562 private static function redirect_after_submit_using_js( $args ) {
2626 2563 $success_msg = FrmOnSubmitHelper::get_default_redirect_msg();
2627 2564 $redirect_msg = self::get_redirect_message( $args['success_url'], $success_msg, $args );
2628 - $success_url = esc_url_raw( $args['success_url'] );
2629 2565
2630 2566 /**
2631 2567 * Filters the delay time before redirecting when On Submit Redirect action is delayed.
2632 2568 *
@@ -2635,14 +2571,8 @@
2635 2571 * @param int $delay_time Delay time in miliseconds.
2636 2572 */
2637 2573 $delay_time = apply_filters( 'frm_redirect_delay_time', 8000 );
2638 2574
2639 - if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
2640 - $redirect_js = 'window.open("' . $success_url . '", "_blank")';
2641 - } else {
2642 - $redirect_js = 'window.location="' . $success_url . '";';
2643 - }
2644 -
2645 2575 add_filter( 'frm_use_wpautop', '__return_true' );
2646 2576
2647 2577 echo FrmAppHelper::maybe_kses( $redirect_msg ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2648 2578 echo '<script>';
@@ -2648,9 +2578,9 @@
2648 2578 echo '<script>';
2649 2579 if ( empty( $args['doing_ajax'] ) ) { // Not AJAX submit, delay JS until window.load.
2650 2580 echo 'window.onload=function(){';
2651 2581 }
2652 - echo 'setTimeout(function(){' . $redirect_js . '}, ' . intval( $delay_time ) . ');'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2582 + echo 'setTimeout(function(){window.location="' . esc_url_raw( $args['success_url'] ) . '";}, ' . intval( $delay_time ) . ');';
2653 2583 if ( empty( $args['doing_ajax'] ) ) {
2654 2584 echo '};';
2655 2585 }
2656 2586 echo '</script>';
@@ -2664,9 +2594,10 @@
2664 2594 * @param array $args
2665 2595 */
2666 2596 private static function get_redirect_message( $success_url, $success_msg, $args ) {
2667 2597 $redirect_msg = '<div class="' . esc_attr( FrmFormsHelper::get_form_style_class( $args['form'] ) ) . '"><div class="frm-redirect-msg" role="status">' . $success_msg . '<br/>' .
2668 - self::get_redirect_fallback_message( $success_url, $args ) .
2598 + /* translators: %1$s: Start link HTML, %2$s: End link HTML */
2599 + sprintf( __( '%1$sClick here%2$s if you are not automatically redirected.', 'formidable' ), '<a href="' . esc_url( $success_url ) . '">', '</a>' ) .
2669 2600 '</div></div>';
2670 2601
2671 2602 $redirect_args = array(
2672 2603 'entry_id' => $args['entry_id'],
@@ -2674,31 +2605,8 @@
2674 2605 'form' => $args['form'],
2675 2606 );
2676 2607
2677 2608 return apply_filters( 'frm_redirect_msg', $redirect_msg, $redirect_args );
2678 - }
2679 -
2680 - /**
2681 - * Gets fallback message when redirecting failed.
2682 - *
2683 - * @since 6.3.1
2684 - *
2685 - * @param string $success_url Redirect URL.
2686 - * @param array $args Contains `form` object.
2687 - * @return string
2688 - */
2689 - private static function get_redirect_fallback_message( $success_url, $args ) {
2690 - $target = '';
2691 - if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
2692 - $target = ' target="_blank"';
2693 - }
2694 -
2695 - return sprintf(
2696 - /* translators: %1$s: Start link HTML, %2$s: End link HTML */
2697 - __( '%1$sClick here%2$s if you are not automatically redirected.', 'formidable' ),
2698 - '<a href="' . esc_url( $success_url ) . '"' . $target . '>',
2699 - '</a>'
2700 - );
2701 2609 }
2702 2610
2703 2611 /**
2704 2612 * Prepare to show the success message and empty form after submit