PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.1
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 +127 -120 6.36.1 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
@@ -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,21 @@
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';
2128 + $opt = 'success_action';
2139 2129 $method = ( isset( $atts['form']->options[ $opt ] ) && ! empty( $atts['form']->options[ $opt ] ) ) ? $atts['form']->options[ $opt ] : 'message';
2140 2130
2141 - if ( ! empty( $atts['entry_id'] ) ) {
2142 - $met_actions = self::get_met_on_submit_actions( $atts, $action );
2131 + if ( ! empty( $atts['entry_id'] ) ) { // Check against entry has already submitted error.
2132 + $met_actions = self::get_met_on_submit_actions( $atts );
2143 2133 if ( $met_actions ) {
2144 2134 $method = $met_actions;
2135 + } else {
2136 + $method = 'message';
2145 2137 }
2146 2138 }
2147 2139
2148 - $method = apply_filters( 'frm_success_filter', $method, $atts['form'], $action );
2140 + $method = apply_filters( 'frm_success_filter', $method, $atts['form'], 'create' );
2149 2141
2150 2142 if ( $method != 'message' && ( ! $atts['entry_id'] || ! is_numeric( $atts['entry_id'] ) ) ) {
2151 2143 $method = 'message';
2152 2144 }
@@ -2163,30 +2155,14 @@
2163 2155 $conf_method = self::get_confirmation_method(
2164 2156 array(
2165 2157 'form' => $form,
2166 2158 'entry_id' => $params['id'],
2167 - 'action' => FrmOnSubmitHelper::current_event( $params ),
2168 2159 )
2169 2160 );
2170 2161
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 2162 if ( is_array( $conf_method ) && 1 === count( $conf_method ) ) {
2186 2163 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 );
2164 + FrmOnSubmitHelper::populate_on_submit_data( $form->options, $conf_method[0] );
2189 2165 $conf_method = 'redirect';
2190 2166 }
2191 2167 }
2192 2168
@@ -2257,12 +2233,8 @@
2257 2233 * @param string $event Form event. Default is `create`.
2258 2234 * @return array Array of actions that meet the conditional logics.
2259 2235 */
2260 2236 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 2237 $entry = FrmEntry::getOne( $args['entry_id'], true );
2266 2238 $actions = FrmOnSubmitHelper::get_actions( $args['form']->id );
2267 2239 $met_actions = array();
2268 2240 $has_redirect = false;
@@ -2275,21 +2247,13 @@
2275 2247 if ( FrmFormAction::action_conditions_met( $action, $entry ) ) {
2276 2248 continue;
2277 2249 }
2278 2250
2279 - $action_type = FrmOnSubmitHelper::get_action_type( $action );
2280 -
2281 - if ( 'redirect' === $action_type ) {
2251 + if ( 'redirect' === FrmOnSubmitHelper::get_action_type( $action ) ) {
2282 2252 if ( $has_redirect ) { // Do not process because we run the first redirect action only.
2283 2253 continue;
2284 2254 }
2285 - }
2286 2255
2287 - if ( ! self::is_valid_on_submit_action( $action, $args, $event ) ) {
2288 - continue;
2289 - }
2290 -
2291 - if ( 'redirect' === $action_type ) {
2292 2256 $has_redirect = true;
2293 2257 }
2294 2258
2295 2259 $met_actions[] = $action;
@@ -2305,57 +2269,12 @@
2305 2269 *
2306 2270 * @param array $met_actions Actions that meet the conditional logics.
2307 2271 * @param array $args See {@see FrmFormsController::run_success_action()}. `$args['event']` is also added.
2308 2272 */
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;
2273 + return apply_filters( 'frm_get_met_on_submit_actions', $met_actions, $args );
2316 2274 }
2317 2275
2318 2276 /**
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 2277 * Runs On Submit actions.
2359 2278 *
2360 2279 * @since 6.0
2361 2280 *
@@ -2360,16 +2279,9 @@
2360 2279 * @since 6.0
2361 2280 *
2362 2281 * @param array $args See inside {@see FrmFormsController::get_form_contents()} method.
2363 2282 */
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 - );
2283 + private static function run_on_submit_actions( $args ) {
2372 2284 if ( ! is_array( $args['conf_method'] ) ) {
2373 2285 self::run_success_action( $args );
2374 2286 return;
2375 2287 }
@@ -2586,19 +2498,9 @@
2586 2498 public static function show_message_after_save( $atts ) {
2587 2499 $atts['message'] = self::prepare_submit_message( $atts['form'], $atts['entry_id'], $atts );
2588 2500
2589 2501 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 - }
2502 + self::show_form_after_submit( $atts );
2601 2503 } else {
2602 2504 self::show_lone_success_messsage( $atts );
2603 2505 }
2604 2506 }
@@ -2668,16 +2570,8 @@
2668 2570 *
2669 2571 * @since 2.05
2670 2572 */
2671 2573 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 2574 $defaults = array(
2681 2575 'errors' => array(),
2682 2576 'message' => '',
2683 2577 'fields' => array(),
@@ -2968,8 +2862,105 @@
2968 2862 );
2969 2863 }
2970 2864
2971 2865 /**
2866 + * Maybe migrate submit settings from the form options to On Submit action.
2867 + * This is added after On Submit action is released. This might migrate the frontend editing submit settings too.
2868 + *
2869 + * @since 6.0
2870 + *
2871 + * @param int $form_id Form ID.
2872 + */
2873 + private static function maybe_migrate_submit_settings_to_action( $form_id ) {
2874 + $form = FrmDb::get_row( 'frm_forms', array( 'id' => $form_id ), 'options,editable' );
2875 + if ( ! $form ) {
2876 + return;
2877 + }
2878 +
2879 + FrmAppHelper::unserialize_or_decode( $form->options );
2880 +
2881 + $flag_key = 'on_submit_migrated';
2882 + if ( ! empty( $form->options[ $flag_key ] ) ) {
2883 + return;
2884 + }
2885 +
2886 + $form->id = $form_id;
2887 +
2888 + // Create On Submit action.
2889 + $base_action = array();
2890 +
2891 + $base_action['post_type'] = FrmFormActionsController::$action_post_type;
2892 + $base_action['post_excerpt'] = FrmOnSubmitAction::$slug;
2893 + $base_action['post_title'] = FrmOnSubmitAction::get_name();
2894 + $base_action['menu_order'] = $form_id;
2895 + $base_action['post_status'] = 'publish';
2896 + $base_action['post_content'] = array(
2897 + 'event' => array( 'create' ),
2898 + );
2899 +
2900 + $action_data = self::get_on_submit_action_data_from_form_options( $form->options );
2901 +
2902 + // If frontend editing is enabled, migrate its settings too.
2903 + if ( method_exists( 'FrmProFormActionsController', 'change_on_submit_action_ops' ) && FrmAppHelper::pro_is_connected() && $form->editable ) {
2904 + $edit_data = self::get_on_submit_action_data_from_form_options( $form->options, 'update' );
2905 +
2906 + if ( $action_data === $edit_data ) {
2907 + // Just create one action for both create and update if they are the same.
2908 + $base_action['post_content']['event'][] = 'update';
2909 + } else {
2910 + // Create a separate action for update.
2911 + $edit_action = $base_action;
2912 + $edit_action['post_content'] += $edit_data;
2913 + $edit_action['post_content']['event'] = array( 'update' );
2914 +
2915 + $edit_action['post_content'] = FrmAppHelper::prepare_and_encode( $edit_action['post_content'] );
2916 + FrmDb::save_json_post( $edit_action );
2917 + }
2918 + }
2919 +
2920 + $action = $base_action;
2921 + $action['post_content'] += $action_data;
2922 +
2923 + $action['post_content'] = FrmAppHelper::prepare_and_encode( $action['post_content'] );
2924 + FrmDb::save_json_post( $action );
2925 +
2926 + $form->options[ $flag_key ] = 1;
2927 + FrmForm::update( $form->id, array( 'options' => $form->options ) );
2928 + }
2929 +
2930 + /**
2931 + * Gets On Submit action data from form options to be used for the migration.
2932 + *
2933 + * @since 6.0
2934 + *
2935 + * @param array $form_options Form options.
2936 + * @param string $event Action event. Accepts `create` or `update`. Default is `create`.
2937 + * @return array
2938 + */
2939 + private static function get_on_submit_action_data_from_form_options( $form_options, $event = 'create' ) {
2940 + $opt = 'update' === $event ? 'edit_' : 'success_';
2941 + $data = array(
2942 + 'success_action' => isset( $form_options[ $opt . 'action' ] ) ? $form_options[ $opt . 'action' ] : FrmOnSubmitHelper::get_default_action_type(),
2943 + );
2944 +
2945 + switch ( $data['success_action'] ) {
2946 + case 'redirect':
2947 + $data['success_url'] = isset( $form_options[ $opt . 'url' ] ) ? $form_options[ $opt . 'url' ] : '';
2948 + break;
2949 +
2950 + case 'page':
2951 + $data['success_page_id'] = isset( $form_options[ $opt . 'page_id' ] ) ? $form_options[ $opt . 'page_id' ] : '';
2952 + break;
2953 +
2954 + default:
2955 + $data['success_msg'] = isset( $form_options[ $opt . 'msg' ] ) ? $form_options[ $opt . 'msg' ] : FrmOnSubmitHelper::get_default_msg();
2956 + $data['show_form'] = ! empty( $form_options['show_form'] );
2957 + }
2958 +
2959 + return $data;
2960 + }
2961 +
2962 + /**
2972 2963 * @deprecated 4.0
2973 2964 */
2974 2965 public static function new_form( $values = array() ) {
2975 2966 FrmDeprecated::new_form( $values );
@@ -2983,13 +2974,29 @@
2983 2974 self::update( $values );
2984 2975 }
2985 2976
2986 2977 /**
2978 + * @deprecated 1.07.05
2979 + * @codeCoverageIgnore
2980 + */
2981 + public static function add_default_templates( $path, $default = true, $template = true ) {
2982 + FrmDeprecated::add_default_templates( $path, $default, $template );
2983 + }
2984 +
2985 + /**
2987 2986 * @deprecated 3.0
2988 2987 * @codeCoverageIgnore
2989 2988 */
2990 2989 public static function bulk_create_template( $ids ) {
2991 2990 return FrmDeprecated::bulk_create_template( $ids );
2991 + }
2992 +
2993 + /**
2994 + * @deprecated 2.03
2995 + * @codeCoverageIgnore
2996 + */
2997 + public static function register_pro_scripts() {
2998 + FrmDeprecated::register_pro_scripts();
2992 2999 }
2993 3000
2994 3001 /**
2995 3002 * @deprecated 3.0