PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.2.3
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.2.3
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 +12 -134 6.5.16.2.3 View file →
@@ -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)';
@@ -889,14 +879,14 @@
889 879 * @return array<string,string>
890 880 */
891 881 public static function get_columns( $columns ) {
892 882 $columns['cb'] = '<input type="checkbox" />';
893 - $columns['name'] = esc_html__( 'Form Title', 'formidable' );
894 - $columns['entries'] = esc_html__( 'Entries', 'formidable' );
883 + $columns['name'] = __( 'Form Title', 'formidable' );
884 + $columns['entries'] = __( 'Entries', 'formidable' );
895 885 $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' );
886 + $columns['form_key'] = __( 'Key', 'formidable' );
887 + $columns['shortcode'] = __( 'Actions', 'formidable' );
888 + $columns['created_at'] = __( 'Date', 'formidable' );
899 889
900 890 add_screen_option(
901 891 'per_page',
902 892 array(
@@ -1269,21 +1259,8 @@
1269 1259 'screenshot' => 'chat.png',
1270 1260 )
1271 1261 ),
1272 1262 ),
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 1263 'html' => array(
1287 1264 'name' => __( 'Customize HTML', 'formidable' ),
1288 1265 'class' => __CLASS__,
1289 1266 'function' => 'html_settings',
@@ -1290,9 +1267,9 @@
1290 1267 'icon' => 'frm_icon_font frm_code_icon',
1291 1268 ),
1292 1269 );
1293 1270
1294 - foreach ( array( 'landing', 'chat', 'abandonment' ) as $feature ) {
1271 + foreach ( array( 'landing', 'chat' ) as $feature ) {
1295 1272 if ( ! FrmAppHelper::show_new_feature( $feature ) ) {
1296 1273 unset( $sections[ $feature ] );
1297 1274 }
1298 1275 }
@@ -1628,17 +1605,13 @@
1628 1605 * Replace any [form_name] shortcodes in a string.
1629 1606 *
1630 1607 * @since 5.5
1631 1608 *
1632 - * @param string|array $string
1609 + * @param string $string
1633 1610 * @param stdClass|string|int $form
1634 - * @return string|array
1611 + * @return string
1635 1612 */
1636 1613 public static function replace_form_name_shortcodes( $string, $form ) {
1637 - if ( ! is_string( $string ) ) {
1638 - return $string;
1639 - }
1640 -
1641 1614 if ( false === strpos( $string, '[form_name]' ) ) {
1642 1615 return $string;
1643 1616 }
1644 1617
@@ -2288,13 +2261,8 @@
2288 2261 if ( ! FrmOnSubmitHelper::form_has_migrated( $args['form'] ) ) {
2289 2262 return array();
2290 2263 }
2291 2264
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 2265 $entry = FrmEntry::getOne( $args['entry_id'], true );
2298 2266 $actions = FrmOnSubmitHelper::get_actions( $args['form']->id );
2299 2267 $met_actions = array();
2300 2268 $has_redirect = false;
@@ -2540,19 +2508,13 @@
2540 2508
2541 2509 $doing_ajax = FrmAppHelper::doing_ajax();
2542 2510
2543 2511 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' ) ) );
2512 + echo json_encode( array( 'redirect' => $success_url ) );
2545 2513 wp_die();
2546 2514 }
2547 2515
2548 2516 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 2517 wp_redirect( esc_url_raw( $success_url ) );
2556 2518 die(); // do not use wp_die or redirect fails
2557 2519 }
2558 2520
@@ -2560,63 +2522,8 @@
2560 2522 self::redirect_after_submit_using_js( $args + compact( 'success_url', 'doing_ajax' ) );
2561 2523 }
2562 2524
2563 2525 /**
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 2526 * Redirects after submitting using JS. This is used when showing message before redirecting.
2620 2527 *
2621 2528 * @since 6.0
2622 2529 *
@@ -2624,9 +2531,8 @@
2624 2531 */
2625 2532 private static function redirect_after_submit_using_js( $args ) {
2626 2533 $success_msg = FrmOnSubmitHelper::get_default_redirect_msg();
2627 2534 $redirect_msg = self::get_redirect_message( $args['success_url'], $success_msg, $args );
2628 - $success_url = esc_url_raw( $args['success_url'] );
2629 2535
2630 2536 /**
2631 2537 * Filters the delay time before redirecting when On Submit Redirect action is delayed.
2632 2538 *
@@ -2635,14 +2541,8 @@
2635 2541 * @param int $delay_time Delay time in miliseconds.
2636 2542 */
2637 2543 $delay_time = apply_filters( 'frm_redirect_delay_time', 8000 );
2638 2544
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 2545 add_filter( 'frm_use_wpautop', '__return_true' );
2646 2546
2647 2547 echo FrmAppHelper::maybe_kses( $redirect_msg ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2648 2548 echo '<script>';
@@ -2648,9 +2548,9 @@
2648 2548 echo '<script>';
2649 2549 if ( empty( $args['doing_ajax'] ) ) { // Not AJAX submit, delay JS until window.load.
2650 2550 echo 'window.onload=function(){';
2651 2551 }
2652 - 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 ) . ');';
2653 2553 if ( empty( $args['doing_ajax'] ) ) {
2654 2554 echo '};';
2655 2555 }
2656 2556 echo '</script>';
@@ -2664,9 +2564,10 @@
2664 2564 * @param array $args
2665 2565 */
2666 2566 private static function get_redirect_message( $success_url, $success_msg, $args ) {
2667 2567 $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 ) .
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>' ) .
2669 2570 '</div></div>';
2670 2571
2671 2572 $redirect_args = array(
2672 2573 'entry_id' => $args['entry_id'],
@@ -2674,31 +2575,8 @@
2674 2575 'form' => $args['form'],
2675 2576 );
2676 2577
2677 2578 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 2579 }
2702 2580
2703 2581 /**
2704 2582 * Prepare to show the success message and empty form after submit