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 +131 -134 6.36.0 View file →
@@ -139,9 +139,9 @@
139 139 if ( ! $id || ! is_numeric( $id ) ) {
140 140 $id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
141 141 }
142 142
143 - FrmOnSubmitHelper::maybe_migrate_submit_settings_to_action( $id );
143 + self::maybe_migrate_submit_settings_to_action( $id );
144 144
145 145 return self::get_settings_vars( $id, array(), $message );
146 146 }
147 147
@@ -1322,9 +1322,9 @@
1322 1322
1323 1323 /**
1324 1324 * @param array $values
1325 1325 */
1326 - public static function render_spam_settings( $values ) {
1326 + private static function render_spam_settings( $values ) {
1327 1327 if ( function_exists( 'akismet_http_post' ) ) {
1328 1328 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/akismet.php';
1329 1329 }
1330 1330 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/honeypot.php';
@@ -1529,12 +1529,9 @@
1529 1529 return $entry_shortcodes;
1530 1530 }
1531 1531
1532 1532 /**
1533 - * Insert the form class setting into the form.
1534 - *
1535 - * @param stdClass $form
1536 - * @return void
1533 + * Insert the form class setting into the form
1537 1534 */
1538 1535 public static function form_classes( $form ) {
1539 1536 if ( isset( $form->options['form_class'] ) ) {
1540 1537 echo esc_attr( sanitize_text_field( $form->options['form_class'] ) );
@@ -1543,12 +1540,8 @@
1543 1540 if ( ! empty( $form->options['js_validate'] ) ) {
1544 1541 echo ' frm_js_validate ';
1545 1542 self::add_js_validate_form_to_global_vars( $form );
1546 1543 }
1547 -
1548 - if ( ! FrmFormsHelper::should_use_pro_for_ajax_submit() && FrmForm::is_ajax_on( $form ) ) {
1549 - echo ' frm_ajax_submit ';
1550 - }
1551 1544 }
1552 1545
1553 1546 /**
1554 1547 * @since 5.0.03
@@ -2052,11 +2045,8 @@
2052 2045 $pass_args['action'] = $params['action'];
2053 2046 $handle_process_here = $params['action'] === 'create' && $params['posted_form_id'] == $form->id && $_POST; // phpcs:ignore WordPress.Security.NonceVerification.Missing
2054 2047
2055 2048 if ( ! $handle_process_here ) {
2056 - FrmFormState::set_initial_value( 'title', $title );
2057 - FrmFormState::set_initial_value( 'description', $description );
2058 -
2059 2049 do_action( 'frm_display_form_action', $params, $fields, $form, $title, $description );
2060 2050 if ( apply_filters( 'frm_continue_to_new', true, $form->id, $params['action'] ) ) {
2061 2051 self::show_form_after_submit( $pass_args );
2062 2052 }
@@ -2070,8 +2060,9 @@
2070 2060 if ( apply_filters( 'frm_continue_to_create', true, $form->id ) ) {
2071 2061 $entry_id = self::just_created_entry( $form->id );
2072 2062 $pass_args['entry_id'] = $entry_id;
2073 2063 $pass_args['reset'] = true;
2064 + $pass_args['conf_method'] = self::get_confirmation_method( compact( 'form', 'entry_id' ) );
2074 2065
2075 2066 self::run_on_submit_actions( $pass_args );
2076 2067
2077 2068 do_action(
@@ -2133,20 +2124,18 @@
2133 2124 * }
2134 2125 * @return string|array
2135 2126 */
2136 2127 private static function get_confirmation_method( $atts ) {
2137 - $action = FrmOnSubmitHelper::current_event( $atts );
2138 - $opt = 'update' === $action ? 'edit_action' : 'success_action';
2139 - $method = ( isset( $atts['form']->options[ $opt ] ) && ! empty( $atts['form']->options[ $opt ] ) ) ? $atts['form']->options[ $opt ] : 'message';
2140 -
2141 - if ( ! empty( $atts['entry_id'] ) ) {
2142 - $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 );
2143 2130 if ( $met_actions ) {
2144 - $method = $met_actions;
2131 + return $met_actions;
2145 2132 }
2146 2133 }
2147 2134
2148 - $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' );
2149 2138
2150 2139 if ( $method != 'message' && ( ! $atts['entry_id'] || ! is_numeric( $atts['entry_id'] ) ) ) {
2151 2140 $method = 'message';
2152 2141 }
@@ -2163,30 +2152,14 @@
2163 2152 $conf_method = self::get_confirmation_method(
2164 2153 array(
2165 2154 'form' => $form,
2166 2155 'entry_id' => $params['id'],
2167 - 'action' => FrmOnSubmitHelper::current_event( $params ),
2168 2156 )
2169 2157 );
2170 2158
2171 - self::maybe_trigger_redirect_with_action( $conf_method, $form, $params, $args );
2172 - }
2173 -
2174 - /**
2175 - * Maybe trigger redirect with the new Confirmation action.
2176 - *
2177 - * @since 6.1.1
2178 - *
2179 - * @param array|string $conf_method Array of confirmation actions or the action type string.
2180 - * @param object $form Form object.
2181 - * @param array $params See {@see FrmFormsController::maybe_trigger_redirect()}.
2182 - * @param array $args See {@see FrmFormsController::maybe_trigger_redirect()}.
2183 - */
2184 - public static function maybe_trigger_redirect_with_action( $conf_method, $form, $params, $args ) {
2185 2159 if ( is_array( $conf_method ) && 1 === count( $conf_method ) ) {
2186 2160 if ( 'redirect' === FrmOnSubmitHelper::get_action_type( $conf_method[0] ) ) {
2187 - $event = FrmOnSubmitHelper::current_event( $params );
2188 - FrmOnSubmitHelper::populate_on_submit_data( $form->options, $conf_method[0], $event );
2161 + FrmOnSubmitHelper::populate_on_submit_data( $form->options, $conf_method[0] );
2189 2162 $conf_method = 'redirect';
2190 2163 }
2191 2164 }
2192 2165
@@ -2257,12 +2230,8 @@
2257 2230 * @param string $event Form event. Default is `create`.
2258 2231 * @return array Array of actions that meet the conditional logics.
2259 2232 */
2260 2233 public static function get_met_on_submit_actions( $args, $event = 'create' ) {
2261 - if ( ! FrmOnSubmitHelper::form_has_migrated( $args['form'] ) ) {
2262 - return array();
2263 - }
2264 -
2265 2234 $entry = FrmEntry::getOne( $args['entry_id'], true );
2266 2235 $actions = FrmOnSubmitHelper::get_actions( $args['form']->id );
2267 2236 $met_actions = array();
2268 2237 $has_redirect = false;
@@ -2275,21 +2244,13 @@
2275 2244 if ( FrmFormAction::action_conditions_met( $action, $entry ) ) {
2276 2245 continue;
2277 2246 }
2278 2247
2279 - $action_type = FrmOnSubmitHelper::get_action_type( $action );
2280 -
2281 - if ( 'redirect' === $action_type ) {
2248 + if ( 'redirect' === FrmOnSubmitHelper::get_action_type( $action ) ) {
2282 2249 if ( $has_redirect ) { // Do not process because we run the first redirect action only.
2283 2250 continue;
2284 2251 }
2285 - }
2286 2252
2287 - if ( ! self::is_valid_on_submit_action( $action, $args, $event ) ) {
2288 - continue;
2289 - }
2290 -
2291 - if ( 'redirect' === $action_type ) {
2292 2253 $has_redirect = true;
2293 2254 }
2294 2255
2295 2256 $met_actions[] = $action;
@@ -2305,57 +2266,12 @@
2305 2266 *
2306 2267 * @param array $met_actions Actions that meet the conditional logics.
2307 2268 * @param array $args See {@see FrmFormsController::run_success_action()}. `$args['event']` is also added.
2308 2269 */
2309 - $met_actions = apply_filters( 'frm_get_met_on_submit_actions', $met_actions, $args );
2310 -
2311 - if ( empty( $met_actions ) ) {
2312 - $met_actions = array( FrmOnSubmitHelper::get_fallback_action( $event ) );
2313 - }
2314 -
2315 - return $met_actions;
2270 + return apply_filters( 'frm_get_met_on_submit_actions', $met_actions, $args );
2316 2271 }
2317 2272
2318 2273 /**
2319 - * Checks if a Confirmation action has the valid data.
2320 - *
2321 - * @since 6.1.2
2322 - *
2323 - * @param object $action Form action object.
2324 - * @param array $args See {@see FrmFormsController::run_success_action()}.
2325 - * @param string $event Form event. Default is `create`.
2326 - * @return bool
2327 - */
2328 - private static function is_valid_on_submit_action( $action, $args, $event = 'create' ) {
2329 - $action_type = FrmOnSubmitHelper::get_action_type( $action );
2330 -
2331 - if ( 'redirect' === $action_type ) {
2332 - // Run through frm_redirect_url filter. This is used for the valid action check.
2333 - $action->post_content['success_url'] = apply_filters(
2334 - 'frm_redirect_url',
2335 - $action->post_content['success_url'],
2336 - $args['form'],
2337 - $args + array( 'action' => $event )
2338 - );
2339 -
2340 - return ! empty( $action->post_content['success_url'] );
2341 - }
2342 -
2343 - if ( 'page' === $action_type ) {
2344 - if ( empty( $action->post_content['success_page_id'] ) ) {
2345 - return false;
2346 - }
2347 -
2348 - $page = get_post( $action->post_content['success_page_id'] );
2349 - if ( ! $page || 'trash' === $page->post_status ) {
2350 - return false;
2351 - }
2352 - }
2353 -
2354 - return true;
2355 - }
2356 -
2357 - /**
2358 2274 * Runs On Submit actions.
2359 2275 *
2360 2276 * @since 6.0
2361 2277 *
@@ -2360,16 +2276,9 @@
2360 2276 * @since 6.0
2361 2277 *
2362 2278 * @param array $args See inside {@see FrmFormsController::get_form_contents()} method.
2363 2279 */
2364 - public static function run_on_submit_actions( $args ) {
2365 - $args['conf_method'] = self::get_confirmation_method(
2366 - array(
2367 - 'form' => $args['form'],
2368 - 'entry_id' => $args['entry_id'],
2369 - 'action' => FrmOnSubmitHelper::current_event( $args ),
2370 - )
2371 - );
2280 + private static function run_on_submit_actions( $args ) {
2372 2281 if ( ! is_array( $args['conf_method'] ) ) {
2373 2282 self::run_success_action( $args );
2374 2283 return;
2375 2284 }
@@ -2583,22 +2492,12 @@
2583 2492 *
2584 2493 * @since 2.05
2585 2494 */
2586 2495 public static function show_message_after_save( $atts ) {
2587 - $atts['message'] = self::prepare_submit_message( $atts['form'], $atts['entry_id'], $atts );
2496 + $atts['message'] = self::prepare_submit_message( $atts['form'], $atts['entry_id'] );
2588 2497
2589 2498 if ( ! isset( $atts['form']->options['show_form'] ) || $atts['form']->options['show_form'] ) {
2590 - if ( isset( $atts['action'] ) && 'update' === $atts['action'] && is_callable( array( 'FrmProEntriesController', 'show_front_end_form_with_entry' ) ) ) {
2591 - $entry = FrmEntry::getOne( $atts['entry_id'] );
2592 - if ( $entry ) {
2593 - // This is copied from the Pro plugin.
2594 - $atts['conf_message'] = FrmProEntriesController::confirmation( 'message', $atts['form'], $atts['form']->options, $entry->id, $atts );
2595 - $atts['show_form'] = FrmProEntriesController::is_form_displayed_after_edit( $atts['form'] );
2596 - FrmProEntriesController::show_front_end_form_with_entry( $entry, $atts );
2597 - }
2598 - } else {
2599 - self::show_form_after_submit( $atts );
2600 - }
2499 + self::show_form_after_submit( $atts );
2601 2500 } else {
2602 2501 self::show_lone_success_messsage( $atts );
2603 2502 }
2604 2503 }
@@ -2668,16 +2567,8 @@
2668 2567 *
2669 2568 * @since 2.05
2670 2569 */
2671 2570 private static function fill_atts_for_form_display( &$args ) {
2672 - if ( ! isset( $args['title'] ) && isset( $args['show_title'] ) ) {
2673 - $args['title'] = $args['show_title'];
2674 - }
2675 -
2676 - if ( ! isset( $args['description'] ) && isset( $args['show_description'] ) ) {
2677 - $args['description'] = $args['show_description'];
2678 - }
2679 -
2680 2571 $defaults = array(
2681 2572 'errors' => array(),
2682 2573 'message' => '',
2683 2574 'fields' => array(),
@@ -2711,21 +2602,14 @@
2711 2602 /**
2712 2603 * Prepare the success message before it's shown
2713 2604 *
2714 2605 * @since 2.05
2715 - * @since 6.0.x Added the third parameter.
2716 - *
2717 - * @param object $form Form object.
2718 - * @param int $entry_id Entry ID.
2719 - * @param array $args See {@see FrmFormsController::run_success_action()}.
2720 - * @return string
2721 2606 */
2722 - private static function prepare_submit_message( $form, $entry_id, $args = array() ) {
2607 + private static function prepare_submit_message( $form, $entry_id ) {
2723 2608 $frm_settings = FrmAppHelper::get_settings( array( 'current_form' => $form->id ) );
2724 - $opt = isset( $args['success_opt'] ) ? $args['success_opt'] : 'success';
2725 2609
2726 2610 if ( $entry_id && is_numeric( $entry_id ) ) {
2727 - $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;
2728 2612 $class = 'frm_message';
2729 2613 } else {
2730 2614 $message = $frm_settings->failed_msg;
2731 2615 $class = FrmFormsHelper::form_error_class();
@@ -2968,8 +2852,105 @@
2968 2852 );
2969 2853 }
2970 2854
2971 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 + /**
2972 2953 * @deprecated 4.0
2973 2954 */
2974 2955 public static function new_form( $values = array() ) {
2975 2956 FrmDeprecated::new_form( $values );
@@ -2983,13 +2964,29 @@
2983 2964 self::update( $values );
2984 2965 }
2985 2966
2986 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 + /**
2987 2976 * @deprecated 3.0
2988 2977 * @codeCoverageIgnore
2989 2978 */
2990 2979 public static function bulk_create_template( $ids ) {
2991 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();
2992 2989 }
2993 2990
2994 2991 /**
2995 2992 * @deprecated 3.0