| @@ -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,16 +23,13 @@ | ||
| 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 | - // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 34 | 30 | ?> |
| 35 | - <div class="frm_form_field frm_has_shortcodes frm-mt-sm"> | |
| 31 | + <div class="frm_form_field frm_has_shortcodes"> | |
| 36 | 32 | <label for="<?php echo esc_attr( $id_attr ); ?>" class="screen-reader-text"> |
| 37 | 33 | <?php esc_html_e( 'Message on submit', 'formidable' ); ?> |
| 38 | 34 | </label> |
| 39 | 35 | |
| @@ -53,9 +49,9 @@ | ||
| 53 | 49 | <?php |
| 54 | 50 | $id_attr = $args['action_control']->get_field_id( 'show_form' ); |
| 55 | 51 | $name_attr = $args['action_control']->get_field_name( 'show_form' ); |
| 56 | 52 | ?> |
| 57 | - <div class="frm_form_field frm-h-stack-xs"> | |
| 53 | + <div class="frm_form_field"> | |
| 58 | 54 | <?php |
| 59 | 55 | FrmHtmlHelper::toggle( |
| 60 | 56 | $id_attr, |
| 61 | 57 | $name_attr, |
| @@ -70,9 +66,8 @@ | ||
| 70 | 66 | <?php esc_html_e( 'Show the form with the confirmation message', 'formidable' ); ?> |
| 71 | 67 | </label> |
| 72 | 68 | </div> |
| 73 | 69 | <?php |
| 74 | - // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 75 | 70 | } |
| 76 | 71 | |
| 77 | 72 | /** |
| 78 | 73 | * Shows redirect settings. |
| @@ -85,13 +80,43 @@ | ||
| 85 | 80 | * @type object $form Form data. |
| 86 | 81 | * @type string $action_key Action key. |
| 87 | 82 | * @type array $values Contains `fields` (form fields) and `id` (form ID). |
| 88 | 83 | * } |
| 89 | - * | |
| 90 | - * @return void | |
| 91 | 84 | */ |
| 92 | 85 | public static function show_redirect_settings( $args ) { |
| 93 | - 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 | |
| 94 | 119 | } |
| 95 | 120 | |
| 96 | 121 | /** |
| 97 | 122 | * Shows page settings. |
| @@ -104,17 +129,14 @@ | ||
| 104 | 129 | * @type object $form Form data. |
| 105 | 130 | * @type string $action_key Action key. |
| 106 | 131 | * @type array $values Contains `fields` (form fields) and `id` (form ID). |
| 107 | 132 | * } |
| 108 | - * | |
| 109 | - * @return void | |
| 110 | 133 | */ |
| 111 | 134 | public static function show_page_settings( $args ) { |
| 112 | 135 | $name_attr = $args['action_control']->get_field_name( 'success_page_id' ); |
| 113 | - // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 114 | 136 | ?> |
| 115 | - <div class="frm_form_field frm-mt-xs"> | |
| 116 | - <div class="frm_note_style frm-mt-0 frm-mb-md"> | |
| 137 | + <div class="frm_form_field"> | |
| 138 | + <div class="frm_note_style"> | |
| 117 | 139 | <?php esc_html_e( 'NOTE: The selected page content will be displayed, but the full page will not be loaded. Traditional URL tracking in Google Analytics and similar tools won\'t register a page load event. If precise tracking is essential, consider using the \'Redirect to URL\' option.', 'formidable' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong ?> |
| 118 | 140 | </div> |
| 119 | 141 | <label for="<?php echo esc_attr( $name_attr ); ?>" class="screen-reader-text"> |
| 120 | 142 | <?php esc_html_e( 'Select a page', 'formidable' ); ?> |
| @@ -129,9 +151,8 @@ | ||
| 129 | 151 | ); |
| 130 | 152 | ?> |
| 131 | 153 | </div> |
| 132 | 154 | <?php |
| 133 | - // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 134 | 155 | } |
| 135 | 156 | |
| 136 | 157 | /** |
| 137 | 158 | * Gets all active On Submit form actions for form. |
| @@ -139,15 +160,13 @@ | ||
| 139 | 160 | * action is created during run time. If you use another cache method, please remember to delete the cache in |
| 140 | 161 | * {@see FrmFormAction::save_settings()}. |
| 141 | 162 | * |
| 142 | 163 | * @param int $form_id Form ID. |
| 143 | - * | |
| 144 | 164 | * @return array |
| 145 | 165 | */ |
| 146 | 166 | public static function get_actions( $form_id ) { |
| 147 | 167 | $cache_key = 'frm_on_submit_actions_' . $form_id; |
| 148 | 168 | $actions = wp_cache_get( $cache_key, 'frm_actions' ); |
| 149 | - | |
| 150 | 169 | if ( false !== $actions ) { |
| 151 | 170 | return $actions; |
| 152 | 171 | } |
| 153 | 172 | |
| @@ -159,33 +178,26 @@ | ||
| 159 | 178 | /** |
| 160 | 179 | * Gets On Submit action type (message, redirect or page). |
| 161 | 180 | * |
| 162 | 181 | * @param object $action Form action object. |
| 163 | - * | |
| 164 | 182 | * @return string |
| 165 | 183 | */ |
| 166 | 184 | public static function get_action_type( $action ) { |
| 167 | - 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(); | |
| 168 | 189 | } |
| 169 | 190 | |
| 170 | - /** | |
| 171 | - * @return string | |
| 172 | - */ | |
| 173 | 191 | public static function get_default_action_type() { |
| 174 | 192 | return 'message'; |
| 175 | 193 | } |
| 176 | 194 | |
| 177 | - /** | |
| 178 | - * @return string | |
| 179 | - */ | |
| 180 | 195 | public static function get_default_msg() { |
| 181 | 196 | $msg = FrmAppHelper::get_settings()->success_msg; |
| 182 | 197 | return $msg ? $msg : __( 'Your responses were successfully submitted. Thank you!', 'formidable' ); |
| 183 | 198 | } |
| 184 | 199 | |
| 185 | - /** | |
| 186 | - * @return string | |
| 187 | - */ | |
| 188 | 200 | public static function get_default_redirect_msg() { |
| 189 | 201 | return __( 'Please wait while you are redirected.', 'formidable' ); |
| 190 | 202 | } |
| 191 | 203 | |
| @@ -203,21 +215,17 @@ | ||
| 203 | 215 | /** |
| 204 | 216 | * Adds the first On Submit action data to the form options to be saved. |
| 205 | 217 | * |
| 206 | 218 | * @param int $form_id Form ID. |
| 207 | - * | |
| 208 | - * @return void | |
| 209 | 219 | */ |
| 210 | 220 | public static function save_on_submit_settings( $form_id ) { |
| 211 | 221 | $actions = self::get_actions( $form_id ); |
| 212 | 222 | $first_create_action = null; |
| 213 | 223 | $first_edit_action = null; |
| 214 | - | |
| 215 | 224 | foreach ( $actions as $action ) { |
| 216 | 225 | if ( ! $first_create_action && in_array( 'create', $action->post_content['event'], true ) ) { |
| 217 | 226 | $first_create_action = $action; |
| 218 | 227 | } |
| 219 | - | |
| 220 | 228 | if ( ! $first_edit_action && in_array( 'update', $action->post_content['event'], true ) ) { |
| 221 | 229 | $first_edit_action = $action; |
| 222 | 230 | } |
| 223 | 231 | } |
| @@ -223,18 +231,16 @@ | ||
| 223 | 231 | } |
| 224 | 232 | |
| 225 | 233 | $form_options = array(); |
| 226 | 234 | self::populate_on_submit_data( $form_options, $first_create_action ); |
| 227 | - | |
| 228 | 235 | if ( method_exists( 'FrmProFormActionsController', 'change_on_submit_action_ops' ) && FrmAppHelper::pro_is_connected() ) { |
| 229 | 236 | $form_editable = FrmDb::get_var( 'frm_forms', array( 'id' => $form_id ), 'editable' ); |
| 230 | - | |
| 231 | 237 | if ( $form_editable ) { |
| 232 | 238 | self::populate_on_submit_data( $form_options, $first_edit_action, 'update' ); |
| 233 | 239 | } |
| 234 | 240 | } |
| 235 | 241 | |
| 236 | - if ( $form_options ) { | |
| 242 | + if ( ! empty( $form_options ) ) { | |
| 237 | 243 | $_POST['options'] += $form_options; |
| 238 | 244 | } |
| 239 | 245 | } |
| 240 | 246 | |
| @@ -240,17 +246,14 @@ | ||
| 240 | 246 | |
| 241 | 247 | /** |
| 242 | 248 | * Populates the On Submit data to form options. |
| 243 | 249 | * |
| 244 | - * @param array $form_options Form options. | |
| 245 | - * @param object|null $action Optional. The On Submit action object. | |
| 246 | - * @param string $event Form event. Default is `create`. | |
| 247 | - * | |
| 248 | - * @return void | |
| 250 | + * @param array $form_options Form options. | |
| 251 | + * @param object $action Optional. The On Submit action object. | |
| 252 | + * @param string $event Form event. Default is `create`. | |
| 249 | 253 | */ |
| 250 | 254 | public static function populate_on_submit_data( &$form_options, $action = null, $event = 'create' ) { |
| 251 | 255 | $opt = 'update' === $event ? 'edit_' : 'success_'; |
| 252 | - | |
| 253 | 256 | if ( ! $action || ! is_object( $action ) ) { |
| 254 | 257 | $form_options[ $opt . 'action' ] = self::get_default_action_type(); |
| 255 | 258 | $form_options[ $opt . 'msg' ] = self::get_default_msg(); |
| 256 | 259 | |
| @@ -256,21 +259,18 @@ | ||
| 256 | 259 | |
| 257 | 260 | return; |
| 258 | 261 | } |
| 259 | 262 | |
| 260 | - $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'; | |
| 261 | 264 | |
| 262 | 265 | switch ( $form_options[ $opt . 'action' ] ) { |
| 263 | 266 | case 'redirect': |
| 264 | - $form_options[ $opt . 'url' ] = $action->post_content['success_url'] ?? ''; | |
| 265 | - $form_options['open_in_new_tab'] = ! empty( $action->post_content['open_in_new_tab'] ); | |
| 266 | - $form_options['redirect_delay'] = ! empty( $action->post_content['redirect_delay'] ); | |
| 267 | - $form_options['redirect_delay_time'] = $action->post_content['redirect_delay_time']; | |
| 268 | - $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'] ); | |
| 269 | 269 | break; |
| 270 | 270 | |
| 271 | 271 | case 'page': |
| 272 | - $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'] : ''; | |
| 273 | 273 | break; |
| 274 | 274 | |
| 275 | 275 | default: |
| 276 | 276 | $form_options[ $opt . 'msg' ] = ! empty( $action->post_content['success_msg'] ) ? $action->post_content['success_msg'] : self::get_default_msg(); |
| @@ -284,14 +284,11 @@ | ||
| 284 | 284 | * |
| 285 | 285 | * @since 6.1.1 |
| 286 | 286 | * |
| 287 | 287 | * @param int $form_id Form ID. |
| 288 | - * | |
| 289 | - * @return void | |
| 290 | 288 | */ |
| 291 | 289 | public static function maybe_migrate_submit_settings_to_action( $form_id ) { |
| 292 | 290 | $form = FrmDb::get_row( 'frm_forms', array( 'id' => $form_id ), 'options,editable' ); |
| 293 | - | |
| 294 | 291 | if ( ! $form ) { |
| 295 | 292 | return; |
| 296 | 293 | } |
| 297 | 294 | |
| @@ -305,10 +302,9 @@ | ||
| 305 | 302 | $action_type = FrmOnSubmitAction::$slug; |
| 306 | 303 | |
| 307 | 304 | // Check if form already has form actions to avoid creating duplicates. |
| 308 | 305 | $has_actions = FrmFormAction::form_has_action_type( $form_id, $action_type ); |
| 309 | - | |
| 310 | - if ( $has_actions ) { | |
| 306 | + if ( ! empty( $has_actions ) ) { | |
| 311 | 307 | // Don't migrate again. |
| 312 | 308 | self::save_migrated_success_actions( $form ); |
| 313 | 309 | return; |
| 314 | 310 | } |
| @@ -360,28 +356,27 @@ | ||
| 360 | 356 | * @since 6.1.1 |
| 361 | 357 | * |
| 362 | 358 | * @param array $form_options Form options. |
| 363 | 359 | * @param string $event Action event. Accepts `create` or `update`. Default is `create`. |
| 364 | - * | |
| 365 | 360 | * @return array |
| 366 | 361 | */ |
| 367 | 362 | private static function get_on_submit_action_data_from_form_options( $form_options, $event = 'create' ) { |
| 368 | 363 | $opt = 'update' === $event ? 'edit_' : 'success_'; |
| 369 | 364 | $data = array( |
| 370 | - '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(), | |
| 371 | 366 | ); |
| 372 | 367 | |
| 373 | 368 | switch ( $data['success_action'] ) { |
| 374 | 369 | case 'redirect': |
| 375 | - $data['success_url'] = $form_options[ $opt . 'url' ] ?? ''; | |
| 370 | + $data['success_url'] = isset( $form_options[ $opt . 'url' ] ) ? $form_options[ $opt . 'url' ] : ''; | |
| 376 | 371 | break; |
| 377 | 372 | |
| 378 | 373 | case 'page': |
| 379 | - $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' ] : ''; | |
| 380 | 375 | break; |
| 381 | 376 | |
| 382 | 377 | default: |
| 383 | - $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(); | |
| 384 | 379 | $data['show_form'] = ! empty( $form_options['show_form'] ); |
| 385 | 380 | } |
| 386 | 381 | |
| 387 | 382 | return $data; |
| @@ -392,9 +387,8 @@ | ||
| 392 | 387 | * |
| 393 | 388 | * @since 6.1.1 |
| 394 | 389 | * |
| 395 | 390 | * @param object $form Form object. |
| 396 | - * | |
| 397 | 391 | * @return bool |
| 398 | 392 | */ |
| 399 | 393 | public static function form_has_migrated( $form ) { |
| 400 | 394 | return ! empty( $form->options['on_submit_migrated'] ); |
| @@ -403,9 +397,8 @@ | ||
| 403 | 397 | /** |
| 404 | 398 | * @since 6.1.1 |
| 405 | 399 | * |
| 406 | 400 | * @param object $form Limited form object. |
| 407 | - * | |
| 408 | 401 | * @return void |
| 409 | 402 | */ |
| 410 | 403 | private static function save_migrated_success_actions( $form ) { |
| 411 | 404 | // Options may be an empty string. |
| @@ -425,22 +418,14 @@ | ||
| 425 | 418 | * |
| 426 | 419 | * @return object |
| 427 | 420 | */ |
| 428 | 421 | public static function get_fallback_action( $event = 'create' ) { |
| 429 | - $action = new stdClass(); | |
| 430 | - $default_msg = self::get_default_msg(); | |
| 422 | + $action = new stdClass(); | |
| 431 | 423 | |
| 432 | - if ( current_user_can( 'frm_edit_forms' ) ) { | |
| 433 | - $default_msg .= '<br />'; | |
| 434 | - $default_msg .= '<span style="font-weight: 600; font-style: italic;">'; | |
| 435 | - $default_msg .= __( 'This is the fallback message. No confirmation actions match your conditional logic, or they are invalid.', 'formidable' ); | |
| 436 | - $default_msg .= '</span>'; | |
| 437 | - } | |
| 438 | - | |
| 439 | 424 | $action->post_content = array( |
| 440 | 425 | 'event' => (array) $event, |
| 441 | 426 | 'success_action' => 'message', |
| 442 | - 'success_msg' => $default_msg, | |
| 427 | + 'success_msg' => self::get_default_msg(), | |
| 443 | 428 | ); |
| 444 | 429 | |
| 445 | 430 | return $action; |
| 446 | 431 | } |
| @@ -450,9 +435,8 @@ | ||
| 450 | 435 | * |
| 451 | 436 | * @since 6.3.1 |
| 452 | 437 | * |
| 453 | 438 | * @param array|string $event Uses 'create' or 'update'. |
| 454 | - * | |
| 455 | 439 | * @return object |
| 456 | 440 | */ |
| 457 | 441 | public static function get_fallback_action_after_open_in_new_tab( $event ) { |
| 458 | 442 | $action = self::get_fallback_action( $event ); |
| @@ -465,10 +449,8 @@ | ||
| 465 | 449 | /** |
| 466 | 450 | * Check if the current event has been passed. If not, use create actions. |
| 467 | 451 | * |
| 468 | 452 | * @since 6.1.1 |
| 469 | - * | |
| 470 | - * @param array $atts | |
| 471 | 453 | * |
| 472 | 454 | * @return string |
| 473 | 455 | */ |
| 474 | 456 | public static function current_event( $atts ) { |