PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.0
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.0
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 +143 -284 6.5.36.0 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)';
@@ -149,9 +139,9 @@
149 139 if ( ! $id || ! is_numeric( $id ) ) {
150 140 $id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
151 141 }
152 142
153 - FrmOnSubmitHelper::maybe_migrate_submit_settings_to_action( $id );
143 + self::maybe_migrate_submit_settings_to_action( $id );
154 144
155 145 return self::get_settings_vars( $id, array(), $message );
156 146 }
157 147
@@ -397,29 +387,13 @@
397 387 add_filter( 'is_active_sidebar', '__return_false' );
398 388 FrmStylesController::enqueue_css( 'enqueue', true );
399 389
400 390 if ( false === get_template_part( 'page' ) ) {
401 - if ( function_exists( 'wp_is_block_theme' ) && wp_is_block_theme() ) {
402 - add_filter( 'body_class', 'FrmFormsController::preview_block_theme_body_classnames' );
403 - }
404 391 self::fallback_when_page_template_part_is_not_supported_by_theme();
405 392 }
406 393 }
407 394
408 395 /**
409 - * Add padding to the body for block themes.
410 - *
411 - * @since 6.5.2
412 - *
413 - * @param array $classes The body classes list.
414 - * @return array
415 - */
416 - public static function preview_block_theme_body_classnames( $classes ) {
417 - $classes[] = 'has-global-padding';
418 - return $classes;
419 - }
420 -
421 - /**
422 396 * Not every theme supports get_template_part( 'page' ).
423 397 * When this is not supported, false is returned, and we can handle a fallback.
424 398 */
425 399 private static function fallback_when_page_template_part_is_not_supported_by_theme() {
@@ -905,14 +879,14 @@
905 879 * @return array<string,string>
906 880 */
907 881 public static function get_columns( $columns ) {
908 882 $columns['cb'] = '<input type="checkbox" />';
909 - $columns['name'] = esc_html__( 'Form Title', 'formidable' );
910 - $columns['entries'] = esc_html__( 'Entries', 'formidable' );
883 + $columns['name'] = __( 'Form Title', 'formidable' );
884 + $columns['entries'] = __( 'Entries', 'formidable' );
911 885 $columns['id'] = 'ID';
912 - $columns['form_key'] = esc_html__( 'Key', 'formidable' );
913 - $columns['shortcode'] = esc_html__( 'Actions', 'formidable' );
914 - $columns['created_at'] = esc_html__( 'Date', 'formidable' );
886 + $columns['form_key'] = __( 'Key', 'formidable' );
887 + $columns['shortcode'] = __( 'Actions', 'formidable' );
888 + $columns['created_at'] = __( 'Date', 'formidable' );
915 889
916 890 add_screen_option(
917 891 'per_page',
918 892 array(
@@ -1285,21 +1259,8 @@
1285 1259 'screenshot' => 'chat.png',
1286 1260 )
1287 1261 ),
1288 1262 ),
1289 - 'abandonment' => array(
1290 - 'name' => __( 'Form Abandonment', 'formidable' ),
1291 - 'icon' => 'frm_icon_font frm_abandoned_icon',
1292 - 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1293 - 'data' => FrmAppHelper::get_upgrade_data_params(
1294 - 'abandonment',
1295 - array(
1296 - 'upgrade' => __( 'Form abandonment settings', 'formidable' ),
1297 - 'message' => __( 'Unlock the power of data capture to boost lead generation and master the art of form optimization.', 'formidable' ),
1298 - 'screenshot' => 'abandonment.png',
1299 - )
1300 - ),
1301 - ),
1302 1263 'html' => array(
1303 1264 'name' => __( 'Customize HTML', 'formidable' ),
1304 1265 'class' => __CLASS__,
1305 1266 'function' => 'html_settings',
@@ -1306,9 +1267,9 @@
1306 1267 'icon' => 'frm_icon_font frm_code_icon',
1307 1268 ),
1308 1269 );
1309 1270
1310 - foreach ( array( 'landing', 'chat', 'abandonment' ) as $feature ) {
1271 + foreach ( array( 'landing', 'chat' ) as $feature ) {
1311 1272 if ( ! FrmAppHelper::show_new_feature( $feature ) ) {
1312 1273 unset( $sections[ $feature ] );
1313 1274 }
1314 1275 }
@@ -1361,9 +1322,9 @@
1361 1322
1362 1323 /**
1363 1324 * @param array $values
1364 1325 */
1365 - public static function render_spam_settings( $values ) {
1326 + private static function render_spam_settings( $values ) {
1366 1327 if ( function_exists( 'akismet_http_post' ) ) {
1367 1328 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/akismet.php';
1368 1329 }
1369 1330 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/honeypot.php';
@@ -1568,12 +1529,9 @@
1568 1529 return $entry_shortcodes;
1569 1530 }
1570 1531
1571 1532 /**
1572 - * Insert the form class setting into the form.
1573 - *
1574 - * @param stdClass $form
1575 - * @return void
1533 + * Insert the form class setting into the form
1576 1534 */
1577 1535 public static function form_classes( $form ) {
1578 1536 if ( isset( $form->options['form_class'] ) ) {
1579 1537 echo esc_attr( sanitize_text_field( $form->options['form_class'] ) );
@@ -1582,12 +1540,8 @@
1582 1540 if ( ! empty( $form->options['js_validate'] ) ) {
1583 1541 echo ' frm_js_validate ';
1584 1542 self::add_js_validate_form_to_global_vars( $form );
1585 1543 }
1586 -
1587 - if ( ! FrmFormsHelper::should_use_pro_for_ajax_submit() && FrmForm::is_ajax_on( $form ) ) {
1588 - echo ' frm_ajax_submit ';
1589 - }
1590 1544 }
1591 1545
1592 1546 /**
1593 1547 * @since 5.0.03
@@ -1644,17 +1598,13 @@
1644 1598 * Replace any [form_name] shortcodes in a string.
1645 1599 *
1646 1600 * @since 5.5
1647 1601 *
1648 - * @param string|array $string
1602 + * @param string $string
1649 1603 * @param stdClass|string|int $form
1650 - * @return string|array
1604 + * @return string
1651 1605 */
1652 1606 public static function replace_form_name_shortcodes( $string, $form ) {
1653 - if ( ! is_string( $string ) ) {
1654 - return $string;
1655 - }
1656 -
1657 1607 if ( false === strpos( $string, '[form_name]' ) ) {
1658 1608 return $string;
1659 1609 }
1660 1610
@@ -2095,11 +2045,8 @@
2095 2045 $pass_args['action'] = $params['action'];
2096 2046 $handle_process_here = $params['action'] === 'create' && $params['posted_form_id'] == $form->id && $_POST; // phpcs:ignore WordPress.Security.NonceVerification.Missing
2097 2047
2098 2048 if ( ! $handle_process_here ) {
2099 - FrmFormState::set_initial_value( 'title', $title );
2100 - FrmFormState::set_initial_value( 'description', $description );
2101 -
2102 2049 do_action( 'frm_display_form_action', $params, $fields, $form, $title, $description );
2103 2050 if ( apply_filters( 'frm_continue_to_new', true, $form->id, $params['action'] ) ) {
2104 2051 self::show_form_after_submit( $pass_args );
2105 2052 }
@@ -2113,8 +2060,9 @@
2113 2060 if ( apply_filters( 'frm_continue_to_create', true, $form->id ) ) {
2114 2061 $entry_id = self::just_created_entry( $form->id );
2115 2062 $pass_args['entry_id'] = $entry_id;
2116 2063 $pass_args['reset'] = true;
2064 + $pass_args['conf_method'] = self::get_confirmation_method( compact( 'form', 'entry_id' ) );
2117 2065
2118 2066 self::run_on_submit_actions( $pass_args );
2119 2067
2120 2068 do_action(
@@ -2176,20 +2124,18 @@
2176 2124 * }
2177 2125 * @return string|array
2178 2126 */
2179 2127 private static function get_confirmation_method( $atts ) {
2180 - $action = FrmOnSubmitHelper::current_event( $atts );
2181 - $opt = 'update' === $action ? 'edit_action' : 'success_action';
2182 - $method = ( isset( $atts['form']->options[ $opt ] ) && ! empty( $atts['form']->options[ $opt ] ) ) ? $atts['form']->options[ $opt ] : 'message';
2183 -
2184 - if ( ! empty( $atts['entry_id'] ) ) {
2185 - $met_actions = self::get_met_on_submit_actions( $atts, $action );
2128 + if ( ! empty( $atts['entry_id'] ) ) { // Check against entry has already submitted error.
2129 + $met_actions = self::get_met_on_submit_actions( $atts );
2186 2130 if ( $met_actions ) {
2187 - $method = $met_actions;
2131 + return $met_actions;
2188 2132 }
2189 2133 }
2190 2134
2191 - $method = apply_filters( 'frm_success_filter', $method, $atts['form'], $action );
2135 + $opt = 'success_action';
2136 + $method = ( isset( $atts['form']->options[ $opt ] ) && ! empty( $atts['form']->options[ $opt ] ) ) ? $atts['form']->options[ $opt ] : 'message';
2137 + $method = apply_filters( 'frm_success_filter', $method, $atts['form'], 'create' );
2192 2138
2193 2139 if ( $method != 'message' && ( ! $atts['entry_id'] || ! is_numeric( $atts['entry_id'] ) ) ) {
2194 2140 $method = 'message';
2195 2141 }
@@ -2206,30 +2152,14 @@
2206 2152 $conf_method = self::get_confirmation_method(
2207 2153 array(
2208 2154 'form' => $form,
2209 2155 'entry_id' => $params['id'],
2210 - 'action' => FrmOnSubmitHelper::current_event( $params ),
2211 2156 )
2212 2157 );
2213 2158
2214 - self::maybe_trigger_redirect_with_action( $conf_method, $form, $params, $args );
2215 - }
2216 -
2217 - /**
2218 - * Maybe trigger redirect with the new Confirmation action.
2219 - *
2220 - * @since 6.1.1
2221 - *
2222 - * @param array|string $conf_method Array of confirmation actions or the action type string.
2223 - * @param object $form Form object.
2224 - * @param array $params See {@see FrmFormsController::maybe_trigger_redirect()}.
2225 - * @param array $args See {@see FrmFormsController::maybe_trigger_redirect()}.
2226 - */
2227 - public static function maybe_trigger_redirect_with_action( $conf_method, $form, $params, $args ) {
2228 2159 if ( is_array( $conf_method ) && 1 === count( $conf_method ) ) {
2229 2160 if ( 'redirect' === FrmOnSubmitHelper::get_action_type( $conf_method[0] ) ) {
2230 - $event = FrmOnSubmitHelper::current_event( $params );
2231 - FrmOnSubmitHelper::populate_on_submit_data( $form->options, $conf_method[0], $event );
2161 + FrmOnSubmitHelper::populate_on_submit_data( $form->options, $conf_method[0] );
2232 2162 $conf_method = 'redirect';
2233 2163 }
2234 2164 }
2235 2165
@@ -2300,17 +2230,8 @@
2300 2230 * @param string $event Form event. Default is `create`.
2301 2231 * @return array Array of actions that meet the conditional logics.
2302 2232 */
2303 2233 public static function get_met_on_submit_actions( $args, $event = 'create' ) {
2304 - if ( ! FrmOnSubmitHelper::form_has_migrated( $args['form'] ) ) {
2305 - return array();
2306 - }
2307 -
2308 - // If a redirect action has already opened the URL in a new tab, we show the default message in the currect tab.
2309 - if ( ! empty( self::$redirected_in_new_tab[ $args['form']->id ] ) ) {
2310 - return array( FrmOnSubmitHelper::get_fallback_action_after_open_in_new_tab( $event ) );
2311 - }
2312 -
2313 2234 $entry = FrmEntry::getOne( $args['entry_id'], true );
2314 2235 $actions = FrmOnSubmitHelper::get_actions( $args['form']->id );
2315 2236 $met_actions = array();
2316 2237 $has_redirect = false;
@@ -2323,21 +2244,13 @@
2323 2244 if ( FrmFormAction::action_conditions_met( $action, $entry ) ) {
2324 2245 continue;
2325 2246 }
2326 2247
2327 - $action_type = FrmOnSubmitHelper::get_action_type( $action );
2328 -
2329 - if ( 'redirect' === $action_type ) {
2248 + if ( 'redirect' === FrmOnSubmitHelper::get_action_type( $action ) ) {
2330 2249 if ( $has_redirect ) { // Do not process because we run the first redirect action only.
2331 2250 continue;
2332 2251 }
2333 - }
2334 2252
2335 - if ( ! self::is_valid_on_submit_action( $action, $args, $event ) ) {
2336 - continue;
2337 - }
2338 -
2339 - if ( 'redirect' === $action_type ) {
2340 2253 $has_redirect = true;
2341 2254 }
2342 2255
2343 2256 $met_actions[] = $action;
@@ -2353,57 +2266,12 @@
2353 2266 *
2354 2267 * @param array $met_actions Actions that meet the conditional logics.
2355 2268 * @param array $args See {@see FrmFormsController::run_success_action()}. `$args['event']` is also added.
2356 2269 */
2357 - $met_actions = apply_filters( 'frm_get_met_on_submit_actions', $met_actions, $args );
2358 -
2359 - if ( empty( $met_actions ) ) {
2360 - $met_actions = array( FrmOnSubmitHelper::get_fallback_action( $event ) );
2361 - }
2362 -
2363 - return $met_actions;
2270 + return apply_filters( 'frm_get_met_on_submit_actions', $met_actions, $args );
2364 2271 }
2365 2272
2366 2273 /**
2367 - * Checks if a Confirmation action has the valid data.
2368 - *
2369 - * @since 6.1.2
2370 - *
2371 - * @param object $action Form action object.
2372 - * @param array $args See {@see FrmFormsController::run_success_action()}.
2373 - * @param string $event Form event. Default is `create`.
2374 - * @return bool
2375 - */
2376 - private static function is_valid_on_submit_action( $action, $args, $event = 'create' ) {
2377 - $action_type = FrmOnSubmitHelper::get_action_type( $action );
2378 -
2379 - if ( 'redirect' === $action_type ) {
2380 - // Run through frm_redirect_url filter. This is used for the valid action check.
2381 - $action->post_content['success_url'] = apply_filters(
2382 - 'frm_redirect_url',
2383 - $action->post_content['success_url'],
2384 - $args['form'],
2385 - $args + array( 'action' => $event )
2386 - );
2387 -
2388 - return ! empty( $action->post_content['success_url'] );
2389 - }
2390 -
2391 - if ( 'page' === $action_type ) {
2392 - if ( empty( $action->post_content['success_page_id'] ) ) {
2393 - return false;
2394 - }
2395 -
2396 - $page = get_post( $action->post_content['success_page_id'] );
2397 - if ( ! $page || 'trash' === $page->post_status ) {
2398 - return false;
2399 - }
2400 - }
2401 -
2402 - return true;
2403 - }
2404 -
2405 - /**
2406 2274 * Runs On Submit actions.
2407 2275 *
2408 2276 * @since 6.0
2409 2277 *
@@ -2408,16 +2276,9 @@
2408 2276 * @since 6.0
2409 2277 *
2410 2278 * @param array $args See inside {@see FrmFormsController::get_form_contents()} method.
2411 2279 */
2412 - public static function run_on_submit_actions( $args ) {
2413 - $args['conf_method'] = self::get_confirmation_method(
2414 - array(
2415 - 'form' => $args['form'],
2416 - 'entry_id' => $args['entry_id'],
2417 - 'action' => FrmOnSubmitHelper::current_event( $args ),
2418 - )
2419 - );
2280 + private static function run_on_submit_actions( $args ) {
2420 2281 if ( ! is_array( $args['conf_method'] ) ) {
2421 2282 self::run_success_action( $args );
2422 2283 return;
2423 2284 }
@@ -2556,19 +2417,13 @@
2556 2417
2557 2418 $doing_ajax = FrmAppHelper::doing_ajax();
2558 2419
2559 2420 if ( ! empty( $args['ajax'] ) && $doing_ajax && empty( $args['force_delay_redirect'] ) ) { // Is AJAX submit and there is just one Redirect action runs.
2560 - echo json_encode( self::get_ajax_redirect_response_data( $args + compact( 'success_url' ) ) );
2421 + echo json_encode( array( 'redirect' => $success_url ) );
2561 2422 wp_die();
2562 2423 }
2563 2424
2564 2425 if ( ! headers_sent() && empty( $args['force_delay_redirect'] ) ) { // Not AJAX submit, no headers sent, and there is just one Redirect action runs.
2565 - if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
2566 - self::print_open_in_new_tab_js_with_fallback_handler( $success_url, $args );
2567 - self::$redirected_in_new_tab[ $args['form']->id ] = 1;
2568 - return;
2569 - }
2570 -
2571 2426 wp_redirect( esc_url_raw( $success_url ) );
2572 2427 die(); // do not use wp_die or redirect fails
2573 2428 }
2574 2429
@@ -2576,63 +2431,8 @@
2576 2431 self::redirect_after_submit_using_js( $args + compact( 'success_url', 'doing_ajax' ) );
2577 2432 }
2578 2433
2579 2434 /**
2580 - * Prints open in new tab js with fallback handler.
2581 - *
2582 - * @since 6.3.1
2583 - *
2584 - * @param string $success_url Success URL.
2585 - * @param array $args See {@see FrmFormsController::redirect_after_submit()}.
2586 - */
2587 - private static function print_open_in_new_tab_js_with_fallback_handler( $success_url, $args ) {
2588 - echo '<script>var newTab = window.open("' . esc_url_raw( $success_url ) . '", "_blank");';
2589 - echo 'if ( ! newTab ) {';
2590 -
2591 - $data = array(
2592 - 'formId' => intval( $args['form']->id ),
2593 - 'message' => self::get_redirect_fallback_message( $success_url, $args ),
2594 - );
2595 - // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2596 - echo 'frmShowNewTabFallback = ' . FrmAppHelper::maybe_json_encode( $data ) . ';';
2597 - echo '}</script>';
2598 - }
2599 -
2600 - /**
2601 - * Gets response data for redirect action when AJAX submitting.
2602 - *
2603 - * @since 6.3.1
2604 - *
2605 - * @param array $args See {@see FrmFormsController::run_success_action()}.
2606 - * @return array
2607 - */
2608 - private static function get_ajax_redirect_response_data( $args ) {
2609 - $response_data = array( 'redirect' => $args['success_url'] );
2610 -
2611 - if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
2612 - $response_data['openInNewTab'] = 1;
2613 -
2614 - $args['message'] = FrmOnSubmitHelper::get_default_new_tab_msg();
2615 -
2616 - $args['form']->options['success_msg'] = $args['message'];
2617 - $args['form']->options['edit_msg'] = $args['message'];
2618 - if ( ! isset( $args['fields'] ) ) {
2619 - $args['fields'] = FrmField::get_all_for_form( $args['form']->id );
2620 - }
2621 -
2622 - $args['message'] = self::prepare_submit_message( $args['form'], $args['entry_id'], $args );
2623 -
2624 - ob_start();
2625 - self::show_lone_success_messsage( $args );
2626 - $response_data['content'] = ob_get_clean();
2627 -
2628 - $response_data['fallbackMsg'] = self::get_redirect_fallback_message( $args['success_url'], $args );
2629 - }
2630 -
2631 - return $response_data;
2632 - }
2633 -
2634 - /**
2635 2435 * Redirects after submitting using JS. This is used when showing message before redirecting.
2636 2436 *
2637 2437 * @since 6.0
2638 2438 *
@@ -2640,9 +2440,8 @@
2640 2440 */
2641 2441 private static function redirect_after_submit_using_js( $args ) {
2642 2442 $success_msg = FrmOnSubmitHelper::get_default_redirect_msg();
2643 2443 $redirect_msg = self::get_redirect_message( $args['success_url'], $success_msg, $args );
2644 - $success_url = esc_url_raw( $args['success_url'] );
2645 2444
2646 2445 /**
2647 2446 * Filters the delay time before redirecting when On Submit Redirect action is delayed.
2648 2447 *
@@ -2651,14 +2450,8 @@
2651 2450 * @param int $delay_time Delay time in miliseconds.
2652 2451 */
2653 2452 $delay_time = apply_filters( 'frm_redirect_delay_time', 8000 );
2654 2453
2655 - if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
2656 - $redirect_js = 'window.open("' . $success_url . '", "_blank")';
2657 - } else {
2658 - $redirect_js = 'window.location="' . $success_url . '";';
2659 - }
2660 -
2661 2454 add_filter( 'frm_use_wpautop', '__return_true' );
2662 2455
2663 2456 echo FrmAppHelper::maybe_kses( $redirect_msg ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2664 2457 echo '<script>';
@@ -2664,9 +2457,9 @@
2664 2457 echo '<script>';
2665 2458 if ( empty( $args['doing_ajax'] ) ) { // Not AJAX submit, delay JS until window.load.
2666 2459 echo 'window.onload=function(){';
2667 2460 }
2668 - echo 'setTimeout(function(){' . $redirect_js . '}, ' . intval( $delay_time ) . ');'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2461 + echo 'setTimeout(function(){window.location="' . esc_url_raw( $args['success_url'] ) . '";}, ' . intval( $delay_time ) . ');';
2669 2462 if ( empty( $args['doing_ajax'] ) ) {
2670 2463 echo '};';
2671 2464 }
2672 2465 echo '</script>';
@@ -2680,9 +2473,10 @@
2680 2473 * @param array $args
2681 2474 */
2682 2475 private static function get_redirect_message( $success_url, $success_msg, $args ) {
2683 2476 $redirect_msg = '<div class="' . esc_attr( FrmFormsHelper::get_form_style_class( $args['form'] ) ) . '"><div class="frm-redirect-msg" role="status">' . $success_msg . '<br/>' .
2684 - self::get_redirect_fallback_message( $success_url, $args ) .
2477 + /* translators: %1$s: Start link HTML, %2$s: End link HTML */
2478 + sprintf( __( '%1$sClick here%2$s if you are not automatically redirected.', 'formidable' ), '<a href="' . esc_url( $success_url ) . '">', '</a>' ) .
2685 2479 '</div></div>';
2686 2480
2687 2481 $redirect_args = array(
2688 2482 'entry_id' => $args['entry_id'],
@@ -2693,50 +2487,17 @@
2693 2487 return apply_filters( 'frm_redirect_msg', $redirect_msg, $redirect_args );
2694 2488 }
2695 2489
2696 2490 /**
2697 - * Gets fallback message when redirecting failed.
2698 - *
2699 - * @since 6.3.1
2700 - *
2701 - * @param string $success_url Redirect URL.
2702 - * @param array $args Contains `form` object.
2703 - * @return string
2704 - */
2705 - private static function get_redirect_fallback_message( $success_url, $args ) {
2706 - $target = '';
2707 - if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
2708 - $target = ' target="_blank"';
2709 - }
2710 -
2711 - return sprintf(
2712 - /* translators: %1$s: Start link HTML, %2$s: End link HTML */
2713 - __( '%1$sClick here%2$s if you are not automatically redirected.', 'formidable' ),
2714 - '<a href="' . esc_url( $success_url ) . '"' . $target . '>',
2715 - '</a>'
2716 - );
2717 - }
2718 -
2719 - /**
2720 2491 * Prepare to show the success message and empty form after submit
2721 2492 *
2722 2493 * @since 2.05
2723 2494 */
2724 2495 public static function show_message_after_save( $atts ) {
2725 - $atts['message'] = self::prepare_submit_message( $atts['form'], $atts['entry_id'], $atts );
2496 + $atts['message'] = self::prepare_submit_message( $atts['form'], $atts['entry_id'] );
2726 2497
2727 2498 if ( ! isset( $atts['form']->options['show_form'] ) || $atts['form']->options['show_form'] ) {
2728 - if ( isset( $atts['action'] ) && 'update' === $atts['action'] && is_callable( array( 'FrmProEntriesController', 'show_front_end_form_with_entry' ) ) ) {
2729 - $entry = FrmEntry::getOne( $atts['entry_id'] );
2730 - if ( $entry ) {
2731 - // This is copied from the Pro plugin.
2732 - $atts['conf_message'] = FrmProEntriesController::confirmation( 'message', $atts['form'], $atts['form']->options, $entry->id, $atts );
2733 - $atts['show_form'] = FrmProEntriesController::is_form_displayed_after_edit( $atts['form'] );
2734 - FrmProEntriesController::show_front_end_form_with_entry( $entry, $atts );
2735 - }
2736 - } else {
2737 - self::show_form_after_submit( $atts );
2738 - }
2499 + self::show_form_after_submit( $atts );
2739 2500 } else {
2740 2501 self::show_lone_success_messsage( $atts );
2741 2502 }
2742 2503 }
@@ -2806,16 +2567,8 @@
2806 2567 *
2807 2568 * @since 2.05
2808 2569 */
2809 2570 private static function fill_atts_for_form_display( &$args ) {
2810 - if ( ! isset( $args['title'] ) && isset( $args['show_title'] ) ) {
2811 - $args['title'] = $args['show_title'];
2812 - }
2813 -
2814 - if ( ! isset( $args['description'] ) && isset( $args['show_description'] ) ) {
2815 - $args['description'] = $args['show_description'];
2816 - }
2817 -
2818 2571 $defaults = array(
2819 2572 'errors' => array(),
2820 2573 'message' => '',
2821 2574 'fields' => array(),
@@ -2849,21 +2602,14 @@
2849 2602 /**
2850 2603 * Prepare the success message before it's shown
2851 2604 *
2852 2605 * @since 2.05
2853 - * @since 6.0.x Added the third parameter.
2854 - *
2855 - * @param object $form Form object.
2856 - * @param int $entry_id Entry ID.
2857 - * @param array $args See {@see FrmFormsController::run_success_action()}.
2858 - * @return string
2859 2606 */
2860 - private static function prepare_submit_message( $form, $entry_id, $args = array() ) {
2607 + private static function prepare_submit_message( $form, $entry_id ) {
2861 2608 $frm_settings = FrmAppHelper::get_settings( array( 'current_form' => $form->id ) );
2862 - $opt = isset( $args['success_opt'] ) ? $args['success_opt'] : 'success';
2863 2609
2864 2610 if ( $entry_id && is_numeric( $entry_id ) ) {
2865 - $message = isset( $form->options[ $opt . '_msg' ] ) ? $form->options[ $opt . '_msg' ] : $frm_settings->success_msg;
2611 + $message = isset( $form->options['success_msg'] ) ? $form->options['success_msg'] : $frm_settings->success_msg;
2866 2612 $class = 'frm_message';
2867 2613 } else {
2868 2614 $message = $frm_settings->failed_msg;
2869 2615 $class = FrmFormsHelper::form_error_class();
@@ -3106,8 +2852,105 @@
3106 2852 );
3107 2853 }
3108 2854
3109 2855 /**
2856 + * Maybe migrate submit settings from the form options to On Submit action.
2857 + * This is added after On Submit action is released. This might migrate the frontend editing submit settings too.
2858 + *
2859 + * @since 6.0
2860 + *
2861 + * @param int $form_id Form ID.
2862 + */
2863 + private static function maybe_migrate_submit_settings_to_action( $form_id ) {
2864 + $form = FrmDb::get_row( 'frm_forms', array( 'id' => $form_id ), 'options,editable' );
2865 + if ( ! $form ) {
2866 + return;
2867 + }
2868 +
2869 + FrmAppHelper::unserialize_or_decode( $form->options );
2870 +
2871 + $flag_key = 'on_submit_migrated';
2872 + if ( ! empty( $form->options[ $flag_key ] ) ) {
2873 + return;
2874 + }
2875 +
2876 + $form->id = $form_id;
2877 +
2878 + // Create On Submit action.
2879 + $base_action = array();
2880 +
2881 + $base_action['post_type'] = FrmFormActionsController::$action_post_type;
2882 + $base_action['post_excerpt'] = FrmOnSubmitAction::$slug;
2883 + $base_action['post_title'] = FrmOnSubmitAction::get_name();
2884 + $base_action['menu_order'] = $form_id;
2885 + $base_action['post_status'] = 'publish';
2886 + $base_action['post_content'] = array(
2887 + 'event' => array( 'create' ),
2888 + );
2889 +
2890 + $action_data = self::get_on_submit_action_data_from_form_options( $form->options );
2891 +
2892 + // If frontend editing is enabled, migrate its settings too.
2893 + if ( method_exists( 'FrmProFormActionsController', 'change_on_submit_action_ops' ) && FrmAppHelper::pro_is_connected() && $form->editable ) {
2894 + $edit_data = self::get_on_submit_action_data_from_form_options( $form->options, 'update' );
2895 +
2896 + if ( $action_data === $edit_data ) {
2897 + // Just create one action for both create and update if they are the same.
2898 + $base_action['post_content']['event'][] = 'update';
2899 + } else {
2900 + // Create a separate action for update.
2901 + $edit_action = $base_action;
2902 + $edit_action['post_content'] += $edit_data;
2903 + $edit_action['post_content']['event'] = array( 'update' );
2904 +
2905 + $edit_action['post_content'] = FrmAppHelper::prepare_and_encode( $edit_action['post_content'] );
2906 + FrmDb::save_json_post( $edit_action );
2907 + }
2908 + }
2909 +
2910 + $action = $base_action;
2911 + $action['post_content'] += $action_data;
2912 +
2913 + $action['post_content'] = FrmAppHelper::prepare_and_encode( $action['post_content'] );
2914 + FrmDb::save_json_post( $action );
2915 +
2916 + $form->options[ $flag_key ] = 1;
2917 + FrmForm::update( $form->id, array( 'options' => $form->options ) );
2918 + }
2919 +
2920 + /**
2921 + * Gets On Submit action data from form options to be used for the migration.
2922 + *
2923 + * @since 6.0
2924 + *
2925 + * @param array $form_options Form options.
2926 + * @param string $event Action event. Accepts `create` or `update`. Default is `create`.
2927 + * @return array
2928 + */
2929 + private static function get_on_submit_action_data_from_form_options( $form_options, $event = 'create' ) {
2930 + $opt = 'update' === $event ? 'edit_' : 'success_';
2931 + $data = array(
2932 + 'success_action' => isset( $form_options[ $opt . 'action' ] ) ? $form_options[ $opt . 'action' ] : FrmOnSubmitHelper::get_default_action_type(),
2933 + );
2934 +
2935 + switch ( $data['success_action'] ) {
2936 + case 'redirect':
2937 + $data['success_url'] = isset( $form_options[ $opt . 'url' ] ) ? $form_options[ $opt . 'url' ] : '';
2938 + break;
2939 +
2940 + case 'page':
2941 + $data['success_page_id'] = isset( $form_options[ $opt . 'page_id' ] ) ? $form_options[ $opt . 'page_id' ] : '';
2942 + break;
2943 +
2944 + default:
2945 + $data['success_msg'] = isset( $form_options[ $opt . 'msg' ] ) ? $form_options[ $opt . 'msg' ] : FrmOnSubmitHelper::get_default_msg();
2946 + $data['show_form'] = ! empty( $form_options['show_form'] );
2947 + }
2948 +
2949 + return $data;
2950 + }
2951 +
2952 + /**
3110 2953 * @deprecated 4.0
3111 2954 */
3112 2955 public static function new_form( $values = array() ) {
3113 2956 FrmDeprecated::new_form( $values );
@@ -3121,13 +2964,29 @@
3121 2964 self::update( $values );
3122 2965 }
3123 2966
3124 2967 /**
2968 + * @deprecated 1.07.05
2969 + * @codeCoverageIgnore
2970 + */
2971 + public static function add_default_templates( $path, $default = true, $template = true ) {
2972 + FrmDeprecated::add_default_templates( $path, $default, $template );
2973 + }
2974 +
2975 + /**
3125 2976 * @deprecated 3.0
3126 2977 * @codeCoverageIgnore
3127 2978 */
3128 2979 public static function bulk_create_template( $ids ) {
3129 2980 return FrmDeprecated::bulk_create_template( $ids );
2981 + }
2982 +
2983 + /**
2984 + * @deprecated 2.03
2985 + * @codeCoverageIgnore
2986 + */
2987 + public static function register_pro_scripts() {
2988 + FrmDeprecated::register_pro_scripts();
3130 2989 }
3131 2990
3132 2991 /**
3133 2992 * @deprecated 3.0