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 -268 6.5.26.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
@@ -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 }
@@ -1345,9 +1322,9 @@
1345 1322
1346 1323 /**
1347 1324 * @param array $values
1348 1325 */
1349 - public static function render_spam_settings( $values ) {
1326 + private static function render_spam_settings( $values ) {
1350 1327 if ( function_exists( 'akismet_http_post' ) ) {
1351 1328 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/akismet.php';
1352 1329 }
1353 1330 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/honeypot.php';
@@ -1552,12 +1529,9 @@
1552 1529 return $entry_shortcodes;
1553 1530 }
1554 1531
1555 1532 /**
1556 - * Insert the form class setting into the form.
1557 - *
1558 - * @param stdClass $form
1559 - * @return void
1533 + * Insert the form class setting into the form
1560 1534 */
1561 1535 public static function form_classes( $form ) {
1562 1536 if ( isset( $form->options['form_class'] ) ) {
1563 1537 echo esc_attr( sanitize_text_field( $form->options['form_class'] ) );
@@ -1566,12 +1540,8 @@
1566 1540 if ( ! empty( $form->options['js_validate'] ) ) {
1567 1541 echo ' frm_js_validate ';
1568 1542 self::add_js_validate_form_to_global_vars( $form );
1569 1543 }
1570 -
1571 - if ( ! FrmFormsHelper::should_use_pro_for_ajax_submit() && FrmForm::is_ajax_on( $form ) ) {
1572 - echo ' frm_ajax_submit ';
1573 - }
1574 1544 }
1575 1545
1576 1546 /**
1577 1547 * @since 5.0.03
@@ -1628,17 +1598,13 @@
1628 1598 * Replace any [form_name] shortcodes in a string.
1629 1599 *
1630 1600 * @since 5.5
1631 1601 *
1632 - * @param string|array $string
1602 + * @param string $string
1633 1603 * @param stdClass|string|int $form
1634 - * @return string|array
1604 + * @return string
1635 1605 */
1636 1606 public static function replace_form_name_shortcodes( $string, $form ) {
1637 - if ( ! is_string( $string ) ) {
1638 - return $string;
1639 - }
1640 -
1641 1607 if ( false === strpos( $string, '[form_name]' ) ) {
1642 1608 return $string;
1643 1609 }
1644 1610
@@ -2079,11 +2045,8 @@
2079 2045 $pass_args['action'] = $params['action'];
2080 2046 $handle_process_here = $params['action'] === 'create' && $params['posted_form_id'] == $form->id && $_POST; // phpcs:ignore WordPress.Security.NonceVerification.Missing
2081 2047
2082 2048 if ( ! $handle_process_here ) {
2083 - FrmFormState::set_initial_value( 'title', $title );
2084 - FrmFormState::set_initial_value( 'description', $description );
2085 -
2086 2049 do_action( 'frm_display_form_action', $params, $fields, $form, $title, $description );
2087 2050 if ( apply_filters( 'frm_continue_to_new', true, $form->id, $params['action'] ) ) {
2088 2051 self::show_form_after_submit( $pass_args );
2089 2052 }
@@ -2097,8 +2060,9 @@
2097 2060 if ( apply_filters( 'frm_continue_to_create', true, $form->id ) ) {
2098 2061 $entry_id = self::just_created_entry( $form->id );
2099 2062 $pass_args['entry_id'] = $entry_id;
2100 2063 $pass_args['reset'] = true;
2064 + $pass_args['conf_method'] = self::get_confirmation_method( compact( 'form', 'entry_id' ) );
2101 2065
2102 2066 self::run_on_submit_actions( $pass_args );
2103 2067
2104 2068 do_action(
@@ -2160,20 +2124,18 @@
2160 2124 * }
2161 2125 * @return string|array
2162 2126 */
2163 2127 private static function get_confirmation_method( $atts ) {
2164 - $action = FrmOnSubmitHelper::current_event( $atts );
2165 - $opt = 'update' === $action ? 'edit_action' : 'success_action';
2166 - $method = ( isset( $atts['form']->options[ $opt ] ) && ! empty( $atts['form']->options[ $opt ] ) ) ? $atts['form']->options[ $opt ] : 'message';
2167 -
2168 - if ( ! empty( $atts['entry_id'] ) ) {
2169 - $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 );
2170 2130 if ( $met_actions ) {
2171 - $method = $met_actions;
2131 + return $met_actions;
2172 2132 }
2173 2133 }
2174 2134
2175 - $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' );
2176 2138
2177 2139 if ( $method != 'message' && ( ! $atts['entry_id'] || ! is_numeric( $atts['entry_id'] ) ) ) {
2178 2140 $method = 'message';
2179 2141 }
@@ -2190,30 +2152,14 @@
2190 2152 $conf_method = self::get_confirmation_method(
2191 2153 array(
2192 2154 'form' => $form,
2193 2155 'entry_id' => $params['id'],
2194 - 'action' => FrmOnSubmitHelper::current_event( $params ),
2195 2156 )
2196 2157 );
2197 2158
2198 - self::maybe_trigger_redirect_with_action( $conf_method, $form, $params, $args );
2199 - }
2200 -
2201 - /**
2202 - * Maybe trigger redirect with the new Confirmation action.
2203 - *
2204 - * @since 6.1.1
2205 - *
2206 - * @param array|string $conf_method Array of confirmation actions or the action type string.
2207 - * @param object $form Form object.
2208 - * @param array $params See {@see FrmFormsController::maybe_trigger_redirect()}.
2209 - * @param array $args See {@see FrmFormsController::maybe_trigger_redirect()}.
2210 - */
2211 - public static function maybe_trigger_redirect_with_action( $conf_method, $form, $params, $args ) {
2212 2159 if ( is_array( $conf_method ) && 1 === count( $conf_method ) ) {
2213 2160 if ( 'redirect' === FrmOnSubmitHelper::get_action_type( $conf_method[0] ) ) {
2214 - $event = FrmOnSubmitHelper::current_event( $params );
2215 - FrmOnSubmitHelper::populate_on_submit_data( $form->options, $conf_method[0], $event );
2161 + FrmOnSubmitHelper::populate_on_submit_data( $form->options, $conf_method[0] );
2216 2162 $conf_method = 'redirect';
2217 2163 }
2218 2164 }
2219 2165
@@ -2284,17 +2230,8 @@
2284 2230 * @param string $event Form event. Default is `create`.
2285 2231 * @return array Array of actions that meet the conditional logics.
2286 2232 */
2287 2233 public static function get_met_on_submit_actions( $args, $event = 'create' ) {
2288 - if ( ! FrmOnSubmitHelper::form_has_migrated( $args['form'] ) ) {
2289 - return array();
2290 - }
2291 -
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 2234 $entry = FrmEntry::getOne( $args['entry_id'], true );
2298 2235 $actions = FrmOnSubmitHelper::get_actions( $args['form']->id );
2299 2236 $met_actions = array();
2300 2237 $has_redirect = false;
@@ -2307,21 +2244,13 @@
2307 2244 if ( FrmFormAction::action_conditions_met( $action, $entry ) ) {
2308 2245 continue;
2309 2246 }
2310 2247
2311 - $action_type = FrmOnSubmitHelper::get_action_type( $action );
2312 -
2313 - if ( 'redirect' === $action_type ) {
2248 + if ( 'redirect' === FrmOnSubmitHelper::get_action_type( $action ) ) {
2314 2249 if ( $has_redirect ) { // Do not process because we run the first redirect action only.
2315 2250 continue;
2316 2251 }
2317 - }
2318 2252
2319 - if ( ! self::is_valid_on_submit_action( $action, $args, $event ) ) {
2320 - continue;
2321 - }
2322 -
2323 - if ( 'redirect' === $action_type ) {
2324 2253 $has_redirect = true;
2325 2254 }
2326 2255
2327 2256 $met_actions[] = $action;
@@ -2337,57 +2266,12 @@
2337 2266 *
2338 2267 * @param array $met_actions Actions that meet the conditional logics.
2339 2268 * @param array $args See {@see FrmFormsController::run_success_action()}. `$args['event']` is also added.
2340 2269 */
2341 - $met_actions = apply_filters( 'frm_get_met_on_submit_actions', $met_actions, $args );
2342 -
2343 - if ( empty( $met_actions ) ) {
2344 - $met_actions = array( FrmOnSubmitHelper::get_fallback_action( $event ) );
2345 - }
2346 -
2347 - return $met_actions;
2270 + return apply_filters( 'frm_get_met_on_submit_actions', $met_actions, $args );
2348 2271 }
2349 2272
2350 2273 /**
2351 - * Checks if a Confirmation action has the valid data.
2352 - *
2353 - * @since 6.1.2
2354 - *
2355 - * @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 - * @return bool
2359 - */
2360 - private static function is_valid_on_submit_action( $action, $args, $event = 'create' ) {
2361 - $action_type = FrmOnSubmitHelper::get_action_type( $action );
2362 -
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'] );
2373 - }
2374 -
2375 - if ( 'page' === $action_type ) {
2376 - if ( empty( $action->post_content['success_page_id'] ) ) {
2377 - return false;
2378 - }
2379 -
2380 - $page = get_post( $action->post_content['success_page_id'] );
2381 - if ( ! $page || 'trash' === $page->post_status ) {
2382 - return false;
2383 - }
2384 - }
2385 -
2386 - return true;
2387 - }
2388 -
2389 - /**
2390 2274 * Runs On Submit actions.
2391 2275 *
2392 2276 * @since 6.0
2393 2277 *
@@ -2392,16 +2276,9 @@
2392 2276 * @since 6.0
2393 2277 *
2394 2278 * @param array $args See inside {@see FrmFormsController::get_form_contents()} method.
2395 2279 */
2396 - public static function run_on_submit_actions( $args ) {
2397 - $args['conf_method'] = self::get_confirmation_method(
2398 - array(
2399 - 'form' => $args['form'],
2400 - 'entry_id' => $args['entry_id'],
2401 - 'action' => FrmOnSubmitHelper::current_event( $args ),
2402 - )
2403 - );
2280 + private static function run_on_submit_actions( $args ) {
2404 2281 if ( ! is_array( $args['conf_method'] ) ) {
2405 2282 self::run_success_action( $args );
2406 2283 return;
2407 2284 }
@@ -2540,19 +2417,13 @@
2540 2417
2541 2418 $doing_ajax = FrmAppHelper::doing_ajax();
2542 2419
2543 2420 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' ) ) );
2421 + echo json_encode( array( 'redirect' => $success_url ) );
2545 2422 wp_die();
2546 2423 }
2547 2424
2548 2425 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 2426 wp_redirect( esc_url_raw( $success_url ) );
2556 2427 die(); // do not use wp_die or redirect fails
2557 2428 }
2558 2429
@@ -2560,63 +2431,8 @@
2560 2431 self::redirect_after_submit_using_js( $args + compact( 'success_url', 'doing_ajax' ) );
2561 2432 }
2562 2433
2563 2434 /**
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 2435 * Redirects after submitting using JS. This is used when showing message before redirecting.
2620 2436 *
2621 2437 * @since 6.0
2622 2438 *
@@ -2624,9 +2440,8 @@
2624 2440 */
2625 2441 private static function redirect_after_submit_using_js( $args ) {
2626 2442 $success_msg = FrmOnSubmitHelper::get_default_redirect_msg();
2627 2443 $redirect_msg = self::get_redirect_message( $args['success_url'], $success_msg, $args );
2628 - $success_url = esc_url_raw( $args['success_url'] );
2629 2444
2630 2445 /**
2631 2446 * Filters the delay time before redirecting when On Submit Redirect action is delayed.
2632 2447 *
@@ -2635,14 +2450,8 @@
2635 2450 * @param int $delay_time Delay time in miliseconds.
2636 2451 */
2637 2452 $delay_time = apply_filters( 'frm_redirect_delay_time', 8000 );
2638 2453
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 2454 add_filter( 'frm_use_wpautop', '__return_true' );
2646 2455
2647 2456 echo FrmAppHelper::maybe_kses( $redirect_msg ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2648 2457 echo '<script>';
@@ -2648,9 +2457,9 @@
2648 2457 echo '<script>';
2649 2458 if ( empty( $args['doing_ajax'] ) ) { // Not AJAX submit, delay JS until window.load.
2650 2459 echo 'window.onload=function(){';
2651 2460 }
2652 - 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 ) . ');';
2653 2462 if ( empty( $args['doing_ajax'] ) ) {
2654 2463 echo '};';
2655 2464 }
2656 2465 echo '</script>';
@@ -2664,9 +2473,10 @@
2664 2473 * @param array $args
2665 2474 */
2666 2475 private static function get_redirect_message( $success_url, $success_msg, $args ) {
2667 2476 $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 ) .
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>' ) .
2669 2479 '</div></div>';
2670 2480
2671 2481 $redirect_args = array(
2672 2482 'entry_id' => $args['entry_id'],
@@ -2677,50 +2487,17 @@
2677 2487 return apply_filters( 'frm_redirect_msg', $redirect_msg, $redirect_args );
2678 2488 }
2679 2489
2680 2490 /**
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 - }
2702 -
2703 - /**
2704 2491 * Prepare to show the success message and empty form after submit
2705 2492 *
2706 2493 * @since 2.05
2707 2494 */
2708 2495 public static function show_message_after_save( $atts ) {
2709 - $atts['message'] = self::prepare_submit_message( $atts['form'], $atts['entry_id'], $atts );
2496 + $atts['message'] = self::prepare_submit_message( $atts['form'], $atts['entry_id'] );
2710 2497
2711 2498 if ( ! isset( $atts['form']->options['show_form'] ) || $atts['form']->options['show_form'] ) {
2712 - if ( isset( $atts['action'] ) && 'update' === $atts['action'] && is_callable( array( 'FrmProEntriesController', 'show_front_end_form_with_entry' ) ) ) {
2713 - $entry = FrmEntry::getOne( $atts['entry_id'] );
2714 - if ( $entry ) {
2715 - // This is copied from the Pro plugin.
2716 - $atts['conf_message'] = FrmProEntriesController::confirmation( 'message', $atts['form'], $atts['form']->options, $entry->id, $atts );
2717 - $atts['show_form'] = FrmProEntriesController::is_form_displayed_after_edit( $atts['form'] );
2718 - FrmProEntriesController::show_front_end_form_with_entry( $entry, $atts );
2719 - }
2720 - } else {
2721 - self::show_form_after_submit( $atts );
2722 - }
2499 + self::show_form_after_submit( $atts );
2723 2500 } else {
2724 2501 self::show_lone_success_messsage( $atts );
2725 2502 }
2726 2503 }
@@ -2790,16 +2567,8 @@
2790 2567 *
2791 2568 * @since 2.05
2792 2569 */
2793 2570 private static function fill_atts_for_form_display( &$args ) {
2794 - if ( ! isset( $args['title'] ) && isset( $args['show_title'] ) ) {
2795 - $args['title'] = $args['show_title'];
2796 - }
2797 -
2798 - if ( ! isset( $args['description'] ) && isset( $args['show_description'] ) ) {
2799 - $args['description'] = $args['show_description'];
2800 - }
2801 -
2802 2571 $defaults = array(
2803 2572 'errors' => array(),
2804 2573 'message' => '',
2805 2574 'fields' => array(),
@@ -2833,21 +2602,14 @@
2833 2602 /**
2834 2603 * Prepare the success message before it's shown
2835 2604 *
2836 2605 * @since 2.05
2837 - * @since 6.0.x Added the third parameter.
2838 - *
2839 - * @param object $form Form object.
2840 - * @param int $entry_id Entry ID.
2841 - * @param array $args See {@see FrmFormsController::run_success_action()}.
2842 - * @return string
2843 2606 */
2844 - private static function prepare_submit_message( $form, $entry_id, $args = array() ) {
2607 + private static function prepare_submit_message( $form, $entry_id ) {
2845 2608 $frm_settings = FrmAppHelper::get_settings( array( 'current_form' => $form->id ) );
2846 - $opt = isset( $args['success_opt'] ) ? $args['success_opt'] : 'success';
2847 2609
2848 2610 if ( $entry_id && is_numeric( $entry_id ) ) {
2849 - $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;
2850 2612 $class = 'frm_message';
2851 2613 } else {
2852 2614 $message = $frm_settings->failed_msg;
2853 2615 $class = FrmFormsHelper::form_error_class();
@@ -3090,8 +2852,105 @@
3090 2852 );
3091 2853 }
3092 2854
3093 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 + /**
3094 2953 * @deprecated 4.0
3095 2954 */
3096 2955 public static function new_form( $values = array() ) {
3097 2956 FrmDeprecated::new_form( $values );
@@ -3105,13 +2964,29 @@
3105 2964 self::update( $values );
3106 2965 }
3107 2966
3108 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 + /**
3109 2976 * @deprecated 3.0
3110 2977 * @codeCoverageIgnore
3111 2978 */
3112 2979 public static function bulk_create_template( $ids ) {
3113 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();
3114 2989 }
3115 2990
3116 2991 /**
3117 2992 * @deprecated 3.0