| @@ -4,18 +4,8 @@ | ||
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | class FrmFormsController { |
| 7 | 7 | |
| 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. | |
| 11 | - * | |
| 12 | - * @since 6.2 | |
| 13 | - * | |
| 14 | - * @var array Keys are form IDs and values are 1. | |
| 15 | - */ | |
| 16 | - private static $redirected_in_new_tab = array(); | |
| 17 | - | |
| 18 | 8 | public static function menu() { |
| 19 | 9 | $menu_label = __( 'Forms', 'formidable' ); |
| 20 | 10 | if ( ! FrmAppHelper::pro_is_installed() ) { |
| 21 | 11 | $menu_label .= ' (Lite)'; |
| @@ -1615,17 +1605,13 @@ | ||
| 1615 | 1605 | * Replace any [form_name] shortcodes in a string. |
| 1616 | 1606 | * |
| 1617 | 1607 | * @since 5.5 |
| 1618 | 1608 | * |
| 1619 | - * @param string|array $string | |
| 1609 | + * @param string $string | |
| 1620 | 1610 | * @param stdClass|string|int $form |
| 1621 | - * @return string|array | |
| 1611 | + * @return string | |
| 1622 | 1612 | */ |
| 1623 | 1613 | public static function replace_form_name_shortcodes( $string, $form ) { |
| 1624 | - if ( ! is_string( $string ) ) { | |
| 1625 | - return $string; | |
| 1626 | - } | |
| 1627 | - | |
| 1628 | 1614 | if ( false === strpos( $string, '[form_name]' ) ) { |
| 1629 | 1615 | return $string; |
| 1630 | 1616 | } |
| 1631 | 1617 | |
| @@ -2275,13 +2261,8 @@ | ||
| 2275 | 2261 | if ( ! FrmOnSubmitHelper::form_has_migrated( $args['form'] ) ) { |
| 2276 | 2262 | return array(); |
| 2277 | 2263 | } |
| 2278 | 2264 | |
| 2279 | - // If a redirect action has already opened the URL in a new tab, we show the default message in the currect tab. | |
| 2280 | - if ( ! empty( self::$redirected_in_new_tab[ $args['form']->id ] ) ) { | |
| 2281 | - return array( FrmOnSubmitHelper::get_fallback_action_after_open_in_new_tab( $event ) ); | |
| 2282 | - } | |
| 2283 | - | |
| 2284 | 2265 | $entry = FrmEntry::getOne( $args['entry_id'], true ); |
| 2285 | 2266 | $actions = FrmOnSubmitHelper::get_actions( $args['form']->id ); |
| 2286 | 2267 | $met_actions = array(); |
| 2287 | 2268 | $has_redirect = false; |
| @@ -2527,19 +2508,13 @@ | ||
| 2527 | 2508 | |
| 2528 | 2509 | $doing_ajax = FrmAppHelper::doing_ajax(); |
| 2529 | 2510 | |
| 2530 | 2511 | if ( ! empty( $args['ajax'] ) && $doing_ajax && empty( $args['force_delay_redirect'] ) ) { // Is AJAX submit and there is just one Redirect action runs. |
| 2531 | - echo json_encode( self::get_ajax_redirect_response_data( $args + compact( 'success_url' ) ) ); | |
| 2512 | + echo json_encode( array( 'redirect' => $success_url ) ); | |
| 2532 | 2513 | wp_die(); |
| 2533 | 2514 | } |
| 2534 | 2515 | |
| 2535 | 2516 | if ( ! headers_sent() && empty( $args['force_delay_redirect'] ) ) { // Not AJAX submit, no headers sent, and there is just one Redirect action runs. |
| 2536 | - if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) { | |
| 2537 | - self::print_open_in_new_tab_js_with_fallback_handler( $success_url, $args ); | |
| 2538 | - self::$redirected_in_new_tab[ $args['form']->id ] = 1; | |
| 2539 | - return; | |
| 2540 | - } | |
| 2541 | - | |
| 2542 | 2517 | wp_redirect( esc_url_raw( $success_url ) ); |
| 2543 | 2518 | die(); // do not use wp_die or redirect fails |
| 2544 | 2519 | } |
| 2545 | 2520 | |
| @@ -2547,63 +2522,8 @@ | ||
| 2547 | 2522 | self::redirect_after_submit_using_js( $args + compact( 'success_url', 'doing_ajax' ) ); |
| 2548 | 2523 | } |
| 2549 | 2524 | |
| 2550 | 2525 | /** |
| 2551 | - * Prints open in new tab js with fallback handler. | |
| 2552 | - * | |
| 2553 | - * @since 6.x | |
| 2554 | - * | |
| 2555 | - * @param string $success_url Success URL. | |
| 2556 | - * @param array $args See {@see FrmFormsController::redirect_after_submit()}. | |
| 2557 | - */ | |
| 2558 | - private static function print_open_in_new_tab_js_with_fallback_handler( $success_url, $args ) { | |
| 2559 | - echo '<script>var newTab = window.open("' . esc_url_raw( $success_url ) . '", "_blank");'; | |
| 2560 | - echo 'if ( ! newTab ) {'; | |
| 2561 | - | |
| 2562 | - $data = array( | |
| 2563 | - 'formId' => intval( $args['form']->id ), | |
| 2564 | - 'message' => self::get_redirect_fallback_message( $success_url, $args ), | |
| 2565 | - ); | |
| 2566 | - // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 2567 | - echo 'frmShowNewTabFallback = ' . FrmAppHelper::maybe_json_encode( $data ) . ';'; | |
| 2568 | - echo '}</script>'; | |
| 2569 | - } | |
| 2570 | - | |
| 2571 | - /** | |
| 2572 | - * Gets response data for redirect action when AJAX submitting. | |
| 2573 | - * | |
| 2574 | - * @since 6.x | |
| 2575 | - * | |
| 2576 | - * @param array $args See {@see FrmFormsController::run_success_action()}. | |
| 2577 | - * @return array | |
| 2578 | - */ | |
| 2579 | - private static function get_ajax_redirect_response_data( $args ) { | |
| 2580 | - $response_data = array( 'redirect' => $args['success_url'] ); | |
| 2581 | - | |
| 2582 | - if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) { | |
| 2583 | - $response_data['openInNewTab'] = 1; | |
| 2584 | - | |
| 2585 | - $args['message'] = FrmOnSubmitHelper::get_default_new_tab_msg(); | |
| 2586 | - | |
| 2587 | - $args['form']->options['success_msg'] = $args['message']; | |
| 2588 | - $args['form']->options['edit_msg'] = $args['message']; | |
| 2589 | - if ( ! isset( $args['fields'] ) ) { | |
| 2590 | - $args['fields'] = FrmField::get_all_for_form( $args['form']->id ); | |
| 2591 | - } | |
| 2592 | - | |
| 2593 | - $args['message'] = self::prepare_submit_message( $args['form'], $args['entry_id'], $args ); | |
| 2594 | - | |
| 2595 | - ob_start(); | |
| 2596 | - self::show_lone_success_messsage( $args ); | |
| 2597 | - $response_data['content'] = ob_get_clean(); | |
| 2598 | - | |
| 2599 | - $response_data['fallbackMsg'] = self::get_redirect_fallback_message( $args['success_url'], $args ); | |
| 2600 | - } | |
| 2601 | - | |
| 2602 | - return $response_data; | |
| 2603 | - } | |
| 2604 | - | |
| 2605 | - /** | |
| 2606 | 2526 | * Redirects after submitting using JS. This is used when showing message before redirecting. |
| 2607 | 2527 | * |
| 2608 | 2528 | * @since 6.0 |
| 2609 | 2529 | * |
| @@ -2611,9 +2531,8 @@ | ||
| 2611 | 2531 | */ |
| 2612 | 2532 | private static function redirect_after_submit_using_js( $args ) { |
| 2613 | 2533 | $success_msg = FrmOnSubmitHelper::get_default_redirect_msg(); |
| 2614 | 2534 | $redirect_msg = self::get_redirect_message( $args['success_url'], $success_msg, $args ); |
| 2615 | - $success_url = esc_url_raw( $args['success_url'] ); | |
| 2616 | 2535 | |
| 2617 | 2536 | /** |
| 2618 | 2537 | * Filters the delay time before redirecting when On Submit Redirect action is delayed. |
| 2619 | 2538 | * |
| @@ -2622,14 +2541,8 @@ | ||
| 2622 | 2541 | * @param int $delay_time Delay time in miliseconds. |
| 2623 | 2542 | */ |
| 2624 | 2543 | $delay_time = apply_filters( 'frm_redirect_delay_time', 8000 ); |
| 2625 | 2544 | |
| 2626 | - if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) { | |
| 2627 | - $redirect_js = 'window.open("' . $success_url . '", "_blank")'; | |
| 2628 | - } else { | |
| 2629 | - $redirect_js = 'window.location="' . $success_url . '";'; | |
| 2630 | - } | |
| 2631 | - | |
| 2632 | 2545 | add_filter( 'frm_use_wpautop', '__return_true' ); |
| 2633 | 2546 | |
| 2634 | 2547 | echo FrmAppHelper::maybe_kses( $redirect_msg ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 2635 | 2548 | echo '<script>'; |
| @@ -2635,9 +2548,9 @@ | ||
| 2635 | 2548 | echo '<script>'; |
| 2636 | 2549 | if ( empty( $args['doing_ajax'] ) ) { // Not AJAX submit, delay JS until window.load. |
| 2637 | 2550 | echo 'window.onload=function(){'; |
| 2638 | 2551 | } |
| 2639 | - echo 'setTimeout(function(){' . $redirect_js . '}, ' . intval( $delay_time ) . ');'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 2552 | + echo 'setTimeout(function(){window.location="' . esc_url_raw( $args['success_url'] ) . '";}, ' . intval( $delay_time ) . ');'; | |
| 2640 | 2553 | if ( empty( $args['doing_ajax'] ) ) { |
| 2641 | 2554 | echo '};'; |
| 2642 | 2555 | } |
| 2643 | 2556 | echo '</script>'; |
| @@ -2651,9 +2564,10 @@ | ||
| 2651 | 2564 | * @param array $args |
| 2652 | 2565 | */ |
| 2653 | 2566 | private static function get_redirect_message( $success_url, $success_msg, $args ) { |
| 2654 | 2567 | $redirect_msg = '<div class="' . esc_attr( FrmFormsHelper::get_form_style_class( $args['form'] ) ) . '"><div class="frm-redirect-msg" role="status">' . $success_msg . '<br/>' . |
| 2655 | - self::get_redirect_fallback_message( $success_url, $args ) . | |
| 2568 | + /* translators: %1$s: Start link HTML, %2$s: End link HTML */ | |
| 2569 | + sprintf( __( '%1$sClick here%2$s if you are not automatically redirected.', 'formidable' ), '<a href="' . esc_url( $success_url ) . '">', '</a>' ) . | |
| 2656 | 2570 | '</div></div>'; |
| 2657 | 2571 | |
| 2658 | 2572 | $redirect_args = array( |
| 2659 | 2573 | 'entry_id' => $args['entry_id'], |
| @@ -2661,31 +2575,8 @@ | ||
| 2661 | 2575 | 'form' => $args['form'], |
| 2662 | 2576 | ); |
| 2663 | 2577 | |
| 2664 | 2578 | return apply_filters( 'frm_redirect_msg', $redirect_msg, $redirect_args ); |
| 2665 | - } | |
| 2666 | - | |
| 2667 | - /** | |
| 2668 | - * Gets fallback message when redirecting failed. | |
| 2669 | - * | |
| 2670 | - * @since 6.x | |
| 2671 | - * | |
| 2672 | - * @param string $success_url Redirect URL. | |
| 2673 | - * @param array $args Contains `form` object. | |
| 2674 | - * @return string | |
| 2675 | - */ | |
| 2676 | - private static function get_redirect_fallback_message( $success_url, $args ) { | |
| 2677 | - $target = ''; | |
| 2678 | - if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) { | |
| 2679 | - $target = ' target="_blank"'; | |
| 2680 | - } | |
| 2681 | - | |
| 2682 | - return sprintf( | |
| 2683 | - /* translators: %1$s: Start link HTML, %2$s: End link HTML */ | |
| 2684 | - __( '%1$sClick here%2$s if you are not automatically redirected.', 'formidable' ), | |
| 2685 | - '<a href="' . esc_url( $success_url ) . '"' . $target . '>', | |
| 2686 | - '</a>' | |
| 2687 | - ); | |
| 2688 | 2579 | } |
| 2689 | 2580 | |
| 2690 | 2581 | /** |
| 2691 | 2582 | * Prepare to show the success message and empty form after submit |