| @@ -2,9 +2,8 @@ | ||
| 2 | 2 | /** |
| 3 | 3 | * On Submit action helper |
| 4 | 4 | * |
| 5 | 5 | * @package Formidable |
| 6 | - * | |
| 7 | 6 | * @since 6.0 |
| 8 | 7 | */ |
| 9 | 8 | |
| 10 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
| @@ -24,10 +23,8 @@ | ||
| 24 | 23 | * @type object $form Form data. |
| 25 | 24 | * @type string $action_key Action key. |
| 26 | 25 | * @type array $values Contains `fields` (form fields) and `id` (form ID). |
| 27 | 26 | * } |
| 28 | - * | |
| 29 | - * @return void | |
| 30 | 27 | */ |
| 31 | 28 | public static function show_message_settings( $args ) { |
| 32 | 29 | $id_attr = $args['action_control']->get_field_id( 'success_msg' ); |
| 33 | 30 | ?> |
| @@ -83,13 +80,43 @@ | ||
| 83 | 80 | * @type object $form Form data. |
| 84 | 81 | * @type string $action_key Action key. |
| 85 | 82 | * @type array $values Contains `fields` (form fields) and `id` (form ID). |
| 86 | 83 | * } |
| 87 | - * | |
| 88 | - * @return void | |
| 89 | 84 | */ |
| 90 | 85 | public static function show_redirect_settings( $args ) { |
| 91 | - include FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/on_submit_redirect_settings.php'; | |
| 86 | + $id_attr = $args['action_control']->get_field_id( 'success_url' ); | |
| 87 | + ?> | |
| 88 | + <div class="frm_form_field frm_has_shortcodes"> | |
| 89 | + <label for="<?php echo esc_attr( $id_attr ); ?>"><?php esc_html_e( 'Redirect URL', 'formidable' ); ?></label> | |
| 90 | + <input | |
| 91 | + type="text" | |
| 92 | + id="<?php echo esc_attr( $id_attr ); ?>" | |
| 93 | + name="<?php echo esc_attr( $args['action_control']->get_field_name( 'success_url' ) ); ?>" | |
| 94 | + value="<?php echo esc_attr( $args['form_action']->post_content['success_url'] ); ?>" | |
| 95 | + /> | |
| 96 | + </div> | |
| 97 | + | |
| 98 | + <?php | |
| 99 | + $id_attr = $args['action_control']->get_field_id( 'open_in_new_tab' ); | |
| 100 | + $name_attr = $args['action_control']->get_field_name( 'open_in_new_tab' ); | |
| 101 | + ?> | |
| 102 | + <div class="frm_form_field"> | |
| 103 | + <?php | |
| 104 | + FrmHtmlHelper::toggle( | |
| 105 | + $id_attr, | |
| 106 | + $name_attr, | |
| 107 | + array( | |
| 108 | + 'div_class' => 'with_frm_style frm_toggle', | |
| 109 | + 'checked' => ! empty( $args['form_action']->post_content['open_in_new_tab'] ), | |
| 110 | + 'echo' => true, | |
| 111 | + ) | |
| 112 | + ); | |
| 113 | + ?> | |
| 114 | + <label for="<?php echo esc_attr( $id_attr ); ?>" <?php FrmAppHelper::maybe_add_tooltip( 'new_tab' ); ?>> | |
| 115 | + <?php esc_html_e( 'Open in new tab', 'formidable' ); ?> | |
| 116 | + </label> | |
| 117 | + </div> | |
| 118 | + <?php | |
| 92 | 119 | } |
| 93 | 120 | |
| 94 | 121 | /** |
| 95 | 122 | * Shows page settings. |
| @@ -102,10 +129,8 @@ | ||
| 102 | 129 | * @type object $form Form data. |
| 103 | 130 | * @type string $action_key Action key. |
| 104 | 131 | * @type array $values Contains `fields` (form fields) and `id` (form ID). |
| 105 | 132 | * } |
| 106 | - * | |
| 107 | - * @return void | |
| 108 | 133 | */ |
| 109 | 134 | public static function show_page_settings( $args ) { |
| 110 | 135 | $name_attr = $args['action_control']->get_field_name( 'success_page_id' ); |
| 111 | 136 | ?> |
| @@ -135,15 +160,13 @@ | ||
| 135 | 160 | * action is created during run time. If you use another cache method, please remember to delete the cache in |
| 136 | 161 | * {@see FrmFormAction::save_settings()}. |
| 137 | 162 | * |
| 138 | 163 | * @param int $form_id Form ID. |
| 139 | - * | |
| 140 | 164 | * @return array |
| 141 | 165 | */ |
| 142 | 166 | public static function get_actions( $form_id ) { |
| 143 | 167 | $cache_key = 'frm_on_submit_actions_' . $form_id; |
| 144 | 168 | $actions = wp_cache_get( $cache_key, 'frm_actions' ); |
| 145 | - | |
| 146 | 169 | if ( false !== $actions ) { |
| 147 | 170 | return $actions; |
| 148 | 171 | } |
| 149 | 172 | |
| @@ -155,33 +178,26 @@ | ||
| 155 | 178 | /** |
| 156 | 179 | * Gets On Submit action type (message, redirect or page). |
| 157 | 180 | * |
| 158 | 181 | * @param object $action Form action object. |
| 159 | - * | |
| 160 | 182 | * @return string |
| 161 | 183 | */ |
| 162 | 184 | public static function get_action_type( $action ) { |
| 163 | - return $action->post_content['success_action'] ?? self::get_default_action_type(); | |
| 185 | + if ( isset( $action->post_content['success_action'] ) ) { | |
| 186 | + return $action->post_content['success_action']; | |
| 187 | + } | |
| 188 | + return self::get_default_action_type(); | |
| 164 | 189 | } |
| 165 | 190 | |
| 166 | - /** | |
| 167 | - * @return string | |
| 168 | - */ | |
| 169 | 191 | public static function get_default_action_type() { |
| 170 | 192 | return 'message'; |
| 171 | 193 | } |
| 172 | 194 | |
| 173 | - /** | |
| 174 | - * @return string | |
| 175 | - */ | |
| 176 | 195 | public static function get_default_msg() { |
| 177 | 196 | $msg = FrmAppHelper::get_settings()->success_msg; |
| 178 | 197 | return $msg ? $msg : __( 'Your responses were successfully submitted. Thank you!', 'formidable' ); |
| 179 | 198 | } |
| 180 | 199 | |
| 181 | - /** | |
| 182 | - * @return string | |
| 183 | - */ | |
| 184 | 200 | public static function get_default_redirect_msg() { |
| 185 | 201 | return __( 'Please wait while you are redirected.', 'formidable' ); |
| 186 | 202 | } |
| 187 | 203 | |
| @@ -199,21 +215,17 @@ | ||
| 199 | 215 | /** |
| 200 | 216 | * Adds the first On Submit action data to the form options to be saved. |
| 201 | 217 | * |
| 202 | 218 | * @param int $form_id Form ID. |
| 203 | - * | |
| 204 | - * @return void | |
| 205 | 219 | */ |
| 206 | 220 | public static function save_on_submit_settings( $form_id ) { |
| 207 | 221 | $actions = self::get_actions( $form_id ); |
| 208 | 222 | $first_create_action = null; |
| 209 | 223 | $first_edit_action = null; |
| 210 | - | |
| 211 | 224 | foreach ( $actions as $action ) { |
| 212 | 225 | if ( ! $first_create_action && in_array( 'create', $action->post_content['event'], true ) ) { |
| 213 | 226 | $first_create_action = $action; |
| 214 | 227 | } |
| 215 | - | |
| 216 | 228 | if ( ! $first_edit_action && in_array( 'update', $action->post_content['event'], true ) ) { |
| 217 | 229 | $first_edit_action = $action; |
| 218 | 230 | } |
| 219 | 231 | } |
| @@ -219,12 +231,10 @@ | ||
| 219 | 231 | } |
| 220 | 232 | |
| 221 | 233 | $form_options = array(); |
| 222 | 234 | self::populate_on_submit_data( $form_options, $first_create_action ); |
| 223 | - | |
| 224 | 235 | if ( method_exists( 'FrmProFormActionsController', 'change_on_submit_action_ops' ) && FrmAppHelper::pro_is_connected() ) { |
| 225 | 236 | $form_editable = FrmDb::get_var( 'frm_forms', array( 'id' => $form_id ), 'editable' ); |
| 226 | - | |
| 227 | 237 | if ( $form_editable ) { |
| 228 | 238 | self::populate_on_submit_data( $form_options, $first_edit_action, 'update' ); |
| 229 | 239 | } |
| 230 | 240 | } |
| @@ -239,14 +249,11 @@ | ||
| 239 | 249 | * |
| 240 | 250 | * @param array $form_options Form options. |
| 241 | 251 | * @param object $action Optional. The On Submit action object. |
| 242 | 252 | * @param string $event Form event. Default is `create`. |
| 243 | - * | |
| 244 | - * @return void | |
| 245 | 253 | */ |
| 246 | 254 | public static function populate_on_submit_data( &$form_options, $action = null, $event = 'create' ) { |
| 247 | 255 | $opt = 'update' === $event ? 'edit_' : 'success_'; |
| 248 | - | |
| 249 | 256 | if ( ! $action || ! is_object( $action ) ) { |
| 250 | 257 | $form_options[ $opt . 'action' ] = self::get_default_action_type(); |
| 251 | 258 | $form_options[ $opt . 'msg' ] = self::get_default_msg(); |
| 252 | 259 | |
| @@ -252,21 +259,18 @@ | ||
| 252 | 259 | |
| 253 | 260 | return; |
| 254 | 261 | } |
| 255 | 262 | |
| 256 | - $form_options[ $opt . 'action' ] = $action->post_content['success_action'] ?? 'message'; | |
| 263 | + $form_options[ $opt . 'action' ] = isset( $action->post_content['success_action'] ) ? $action->post_content['success_action'] : 'message'; | |
| 257 | 264 | |
| 258 | 265 | switch ( $form_options[ $opt . 'action' ] ) { |
| 259 | 266 | case 'redirect': |
| 260 | - $form_options[ $opt . 'url' ] = $action->post_content['success_url'] ?? ''; | |
| 261 | - $form_options['open_in_new_tab'] = ! empty( $action->post_content['open_in_new_tab'] ); | |
| 262 | - $form_options['redirect_delay'] = ! empty( $action->post_content['redirect_delay'] ); | |
| 263 | - $form_options['redirect_delay_time'] = $action->post_content['redirect_delay_time']; | |
| 264 | - $form_options['redirect_delay_msg'] = $action->post_content['redirect_delay_msg']; | |
| 267 | + $form_options[ $opt . 'url' ] = isset( $action->post_content['success_url'] ) ? $action->post_content['success_url'] : ''; | |
| 268 | + $form_options['open_in_new_tab'] = ! empty( $action->post_content['open_in_new_tab'] ); | |
| 265 | 269 | break; |
| 266 | 270 | |
| 267 | 271 | case 'page': |
| 268 | - $form_options[ $opt . 'page_id' ] = $action->post_content['success_page_id'] ?? ''; | |
| 272 | + $form_options[ $opt . 'page_id' ] = isset( $action->post_content['success_page_id'] ) ? $action->post_content['success_page_id'] : ''; | |
| 269 | 273 | break; |
| 270 | 274 | |
| 271 | 275 | default: |
| 272 | 276 | $form_options[ $opt . 'msg' ] = ! empty( $action->post_content['success_msg'] ) ? $action->post_content['success_msg'] : self::get_default_msg(); |
| @@ -280,14 +284,11 @@ | ||
| 280 | 284 | * |
| 281 | 285 | * @since 6.1.1 |
| 282 | 286 | * |
| 283 | 287 | * @param int $form_id Form ID. |
| 284 | - * | |
| 285 | - * @return void | |
| 286 | 288 | */ |
| 287 | 289 | public static function maybe_migrate_submit_settings_to_action( $form_id ) { |
| 288 | 290 | $form = FrmDb::get_row( 'frm_forms', array( 'id' => $form_id ), 'options,editable' ); |
| 289 | - | |
| 290 | 291 | if ( ! $form ) { |
| 291 | 292 | return; |
| 292 | 293 | } |
| 293 | 294 | |
| @@ -301,9 +302,8 @@ | ||
| 301 | 302 | $action_type = FrmOnSubmitAction::$slug; |
| 302 | 303 | |
| 303 | 304 | // Check if form already has form actions to avoid creating duplicates. |
| 304 | 305 | $has_actions = FrmFormAction::form_has_action_type( $form_id, $action_type ); |
| 305 | - | |
| 306 | 306 | if ( ! empty( $has_actions ) ) { |
| 307 | 307 | // Don't migrate again. |
| 308 | 308 | self::save_migrated_success_actions( $form ); |
| 309 | 309 | return; |
| @@ -356,28 +356,27 @@ | ||
| 356 | 356 | * @since 6.1.1 |
| 357 | 357 | * |
| 358 | 358 | * @param array $form_options Form options. |
| 359 | 359 | * @param string $event Action event. Accepts `create` or `update`. Default is `create`. |
| 360 | - * | |
| 361 | 360 | * @return array |
| 362 | 361 | */ |
| 363 | 362 | private static function get_on_submit_action_data_from_form_options( $form_options, $event = 'create' ) { |
| 364 | 363 | $opt = 'update' === $event ? 'edit_' : 'success_'; |
| 365 | 364 | $data = array( |
| 366 | - 'success_action' => $form_options[ $opt . 'action' ] ?? self::get_default_action_type(), | |
| 365 | + 'success_action' => isset( $form_options[ $opt . 'action' ] ) ? $form_options[ $opt . 'action' ] : self::get_default_action_type(), | |
| 367 | 366 | ); |
| 368 | 367 | |
| 369 | 368 | switch ( $data['success_action'] ) { |
| 370 | 369 | case 'redirect': |
| 371 | - $data['success_url'] = $form_options[ $opt . 'url' ] ?? ''; | |
| 370 | + $data['success_url'] = isset( $form_options[ $opt . 'url' ] ) ? $form_options[ $opt . 'url' ] : ''; | |
| 372 | 371 | break; |
| 373 | 372 | |
| 374 | 373 | case 'page': |
| 375 | - $data['success_page_id'] = $form_options[ $opt . 'page_id' ] ?? ''; | |
| 374 | + $data['success_page_id'] = isset( $form_options[ $opt . 'page_id' ] ) ? $form_options[ $opt . 'page_id' ] : ''; | |
| 376 | 375 | break; |
| 377 | 376 | |
| 378 | 377 | default: |
| 379 | - $data['success_msg'] = $form_options[ $opt . 'msg' ] ?? self::get_default_msg(); | |
| 378 | + $data['success_msg'] = isset( $form_options[ $opt . 'msg' ] ) ? $form_options[ $opt . 'msg' ] : self::get_default_msg(); | |
| 380 | 379 | $data['show_form'] = ! empty( $form_options['show_form'] ); |
| 381 | 380 | } |
| 382 | 381 | |
| 383 | 382 | return $data; |
| @@ -388,9 +387,8 @@ | ||
| 388 | 387 | * |
| 389 | 388 | * @since 6.1.1 |
| 390 | 389 | * |
| 391 | 390 | * @param object $form Form object. |
| 392 | - * | |
| 393 | 391 | * @return bool |
| 394 | 392 | */ |
| 395 | 393 | public static function form_has_migrated( $form ) { |
| 396 | 394 | return ! empty( $form->options['on_submit_migrated'] ); |
| @@ -399,9 +397,8 @@ | ||
| 399 | 397 | /** |
| 400 | 398 | * @since 6.1.1 |
| 401 | 399 | * |
| 402 | 400 | * @param object $form Limited form object. |
| 403 | - * | |
| 404 | 401 | * @return void |
| 405 | 402 | */ |
| 406 | 403 | private static function save_migrated_success_actions( $form ) { |
| 407 | 404 | // Options may be an empty string. |
| @@ -423,21 +420,12 @@ | ||
| 423 | 420 | */ |
| 424 | 421 | public static function get_fallback_action( $event = 'create' ) { |
| 425 | 422 | $action = new stdClass(); |
| 426 | 423 | |
| 427 | - $default_msg = self::get_default_msg(); | |
| 428 | - | |
| 429 | - if ( current_user_can( 'frm_edit_forms' ) ) { | |
| 430 | - $default_msg .= '<br />'; | |
| 431 | - $default_msg .= '<span style="font-weight: 600; font-style: italic;">'; | |
| 432 | - $default_msg .= __( 'This is the fallback message. No confirmation actions match your conditional logic, or they are invalid.', 'formidable' ); | |
| 433 | - $default_msg .= '</span>'; | |
| 434 | - } | |
| 435 | - | |
| 436 | 424 | $action->post_content = array( |
| 437 | 425 | 'event' => (array) $event, |
| 438 | 426 | 'success_action' => 'message', |
| 439 | - 'success_msg' => $default_msg, | |
| 427 | + 'success_msg' => self::get_default_msg(), | |
| 440 | 428 | ); |
| 441 | 429 | |
| 442 | 430 | return $action; |
| 443 | 431 | } |
| @@ -447,9 +435,8 @@ | ||
| 447 | 435 | * |
| 448 | 436 | * @since 6.3.1 |
| 449 | 437 | * |
| 450 | 438 | * @param array|string $event Uses 'create' or 'update'. |
| 451 | - * | |
| 452 | 439 | * @return object |
| 453 | 440 | */ |
| 454 | 441 | public static function get_fallback_action_after_open_in_new_tab( $event ) { |
| 455 | 442 | $action = self::get_fallback_action( $event ); |
| @@ -462,10 +449,8 @@ | ||
| 462 | 449 | /** |
| 463 | 450 | * Check if the current event has been passed. If not, use create actions. |
| 464 | 451 | * |
| 465 | 452 | * @since 6.1.1 |
| 466 | - * | |
| 467 | - * @param array $atts | |
| 468 | 453 | * |
| 469 | 454 | * @return string |
| 470 | 455 | */ |
| 471 | 456 | public static function current_event( $atts ) { |