PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / trunk
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More vtrunk
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/helpers/FrmOnSubmitHelper.php +53 -11 6.25 → trunk View file →
@@ -2,8 +2,9 @@
2 2 /**
3 3 * On Submit action helper
4 4 *
5 5 * @package Formidable
6 + *
6 7 * @since 6.0
7 8 */
8 9
9 10 if ( ! defined( 'ABSPATH' ) ) {
@@ -23,13 +24,16 @@
23 24 * @type object $form Form data.
24 25 * @type string $action_key Action key.
25 26 * @type array $values Contains `fields` (form fields) and `id` (form ID).
26 27 * }
28 + *
29 + * @return void
27 30 */
28 31 public static function show_message_settings( $args ) {
29 32 $id_attr = $args['action_control']->get_field_id( 'success_msg' );
33 + // phpcs:disable Generic.WhiteSpace.ScopeIndent
30 34 ?>
31 - <div class="frm_form_field frm_has_shortcodes">
35 + <div class="frm_form_field frm_has_shortcodes frm-mt-sm">
32 36 <label for="<?php echo esc_attr( $id_attr ); ?>" class="screen-reader-text">
33 37 <?php esc_html_e( 'Message on submit', 'formidable' ); ?>
34 38 </label>
35 39
@@ -49,9 +53,9 @@
49 53 <?php
50 54 $id_attr = $args['action_control']->get_field_id( 'show_form' );
51 55 $name_attr = $args['action_control']->get_field_name( 'show_form' );
52 56 ?>
53 - <div class="frm_form_field">
57 + <div class="frm_form_field frm-h-stack-xs">
54 58 <?php
55 59 FrmHtmlHelper::toggle(
56 60 $id_attr,
57 61 $name_attr,
@@ -66,8 +70,9 @@
66 70 <?php esc_html_e( 'Show the form with the confirmation message', 'formidable' ); ?>
67 71 </label>
68 72 </div>
69 73 <?php
74 + // phpcs:enable Generic.WhiteSpace.ScopeIndent
70 75 }
71 76
72 77 /**
73 78 * Shows redirect settings.
@@ -80,8 +85,10 @@
80 85 * @type object $form Form data.
81 86 * @type string $action_key Action key.
82 87 * @type array $values Contains `fields` (form fields) and `id` (form ID).
83 88 * }
89 + *
90 + * @return void
84 91 */
85 92 public static function show_redirect_settings( $args ) {
86 93 include FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/on_submit_redirect_settings.php';
87 94 }
@@ -97,14 +104,17 @@
97 104 * @type object $form Form data.
98 105 * @type string $action_key Action key.
99 106 * @type array $values Contains `fields` (form fields) and `id` (form ID).
100 107 * }
108 + *
109 + * @return void
101 110 */
102 111 public static function show_page_settings( $args ) {
103 112 $name_attr = $args['action_control']->get_field_name( 'success_page_id' );
113 + // phpcs:disable Generic.WhiteSpace.ScopeIndent
104 114 ?>
105 - <div class="frm_form_field">
106 - <div class="frm_note_style">
115 + <div class="frm_form_field frm-mt-xs">
116 + <div class="frm_note_style frm-mt-0 frm-mb-md">
107 117 <?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 ?>
108 118 </div>
109 119 <label for="<?php echo esc_attr( $name_attr ); ?>" class="screen-reader-text">
110 120 <?php esc_html_e( 'Select a page', 'formidable' ); ?>
@@ -119,8 +129,9 @@
119 129 );
120 130 ?>
121 131 </div>
122 132 <?php
133 + // phpcs:enable Generic.WhiteSpace.ScopeIndent
123 134 }
124 135
125 136 /**
126 137 * Gets all active On Submit form actions for form.
@@ -128,13 +139,15 @@
128 139 * action is created during run time. If you use another cache method, please remember to delete the cache in
129 140 * {@see FrmFormAction::save_settings()}.
130 141 *
131 142 * @param int $form_id Form ID.
143 + *
132 144 * @return array
133 145 */
134 146 public static function get_actions( $form_id ) {
135 147 $cache_key = 'frm_on_submit_actions_' . $form_id;
136 148 $actions = wp_cache_get( $cache_key, 'frm_actions' );
149 +
137 150 if ( false !== $actions ) {
138 151 return $actions;
139 152 }
140 153
@@ -146,8 +159,9 @@
146 159 /**
147 160 * Gets On Submit action type (message, redirect or page).
148 161 *
149 162 * @param object $action Form action object.
163 + *
150 164 * @return string
151 165 */
152 166 public static function get_action_type( $action ) {
153 167 return $action->post_content['success_action'] ?? self::get_default_action_type();
@@ -152,17 +166,26 @@
152 166 public static function get_action_type( $action ) {
153 167 return $action->post_content['success_action'] ?? self::get_default_action_type();
154 168 }
155 169
170 + /**
171 + * @return string
172 + */
156 173 public static function get_default_action_type() {
157 174 return 'message';
158 175 }
159 176
177 + /**
178 + * @return string
179 + */
160 180 public static function get_default_msg() {
161 181 $msg = FrmAppHelper::get_settings()->success_msg;
162 182 return $msg ? $msg : __( 'Your responses were successfully submitted. Thank you!', 'formidable' );
163 183 }
164 184
185 + /**
186 + * @return string
187 + */
165 188 public static function get_default_redirect_msg() {
166 189 return __( 'Please wait while you are redirected.', 'formidable' );
167 190 }
168 191
@@ -180,17 +203,21 @@
180 203 /**
181 204 * Adds the first On Submit action data to the form options to be saved.
182 205 *
183 206 * @param int $form_id Form ID.
207 + *
208 + * @return void
184 209 */
185 210 public static function save_on_submit_settings( $form_id ) {
186 211 $actions = self::get_actions( $form_id );
187 212 $first_create_action = null;
188 213 $first_edit_action = null;
214 +
189 215 foreach ( $actions as $action ) {
190 216 if ( ! $first_create_action && in_array( 'create', $action->post_content['event'], true ) ) {
191 217 $first_create_action = $action;
192 218 }
219 +
193 220 if ( ! $first_edit_action && in_array( 'update', $action->post_content['event'], true ) ) {
194 221 $first_edit_action = $action;
195 222 }
196 223 }
@@ -196,16 +223,18 @@
196 223 }
197 224
198 225 $form_options = array();
199 226 self::populate_on_submit_data( $form_options, $first_create_action );
227 +
200 228 if ( method_exists( 'FrmProFormActionsController', 'change_on_submit_action_ops' ) && FrmAppHelper::pro_is_connected() ) {
201 229 $form_editable = FrmDb::get_var( 'frm_forms', array( 'id' => $form_id ), 'editable' );
230 +
202 231 if ( $form_editable ) {
203 232 self::populate_on_submit_data( $form_options, $first_edit_action, 'update' );
204 233 }
205 234 }
206 235
207 - if ( ! empty( $form_options ) ) {
236 + if ( $form_options ) {
208 237 $_POST['options'] += $form_options;
209 238 }
210 239 }
211 240
@@ -211,14 +240,17 @@
211 240
212 241 /**
213 242 * Populates the On Submit data to form options.
214 243 *
215 - * @param array $form_options Form options.
216 - * @param object $action Optional. The On Submit action object.
217 - * @param string $event Form event. Default is `create`.
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
218 249 */
219 250 public static function populate_on_submit_data( &$form_options, $action = null, $event = 'create' ) {
220 251 $opt = 'update' === $event ? 'edit_' : 'success_';
252 +
221 253 if ( ! $action || ! is_object( $action ) ) {
222 254 $form_options[ $opt . 'action' ] = self::get_default_action_type();
223 255 $form_options[ $opt . 'msg' ] = self::get_default_msg();
224 256
@@ -252,11 +284,14 @@
252 284 *
253 285 * @since 6.1.1
254 286 *
255 287 * @param int $form_id Form ID.
288 + *
289 + * @return void
256 290 */
257 291 public static function maybe_migrate_submit_settings_to_action( $form_id ) {
258 292 $form = FrmDb::get_row( 'frm_forms', array( 'id' => $form_id ), 'options,editable' );
293 +
259 294 if ( ! $form ) {
260 295 return;
261 296 }
262 297
@@ -270,9 +305,10 @@
270 305 $action_type = FrmOnSubmitAction::$slug;
271 306
272 307 // Check if form already has form actions to avoid creating duplicates.
273 308 $has_actions = FrmFormAction::form_has_action_type( $form_id, $action_type );
274 - if ( ! empty( $has_actions ) ) {
309 +
310 + if ( $has_actions ) {
275 311 // Don't migrate again.
276 312 self::save_migrated_success_actions( $form );
277 313 return;
278 314 }
@@ -324,8 +360,9 @@
324 360 * @since 6.1.1
325 361 *
326 362 * @param array $form_options Form options.
327 363 * @param string $event Action event. Accepts `create` or `update`. Default is `create`.
364 + *
328 365 * @return array
329 366 */
330 367 private static function get_on_submit_action_data_from_form_options( $form_options, $event = 'create' ) {
331 368 $opt = 'update' === $event ? 'edit_' : 'success_';
@@ -355,8 +392,9 @@
355 392 *
356 393 * @since 6.1.1
357 394 *
358 395 * @param object $form Form object.
396 + *
359 397 * @return bool
360 398 */
361 399 public static function form_has_migrated( $form ) {
362 400 return ! empty( $form->options['on_submit_migrated'] );
@@ -365,8 +403,9 @@
365 403 /**
366 404 * @since 6.1.1
367 405 *
368 406 * @param object $form Limited form object.
407 + *
369 408 * @return void
370 409 */
371 410 private static function save_migrated_success_actions( $form ) {
372 411 // Options may be an empty string.
@@ -386,11 +425,11 @@
386 425 *
387 426 * @return object
388 427 */
389 428 public static function get_fallback_action( $event = 'create' ) {
390 - $action = new stdClass();
429 + $action = new stdClass();
430 + $default_msg = self::get_default_msg();
391 431
392 - $default_msg = self::get_default_msg();
393 432 if ( current_user_can( 'frm_edit_forms' ) ) {
394 433 $default_msg .= '<br />';
395 434 $default_msg .= '<span style="font-weight: 600; font-style: italic;">';
396 435 $default_msg .= __( 'This is the fallback message. No confirmation actions match your conditional logic, or they are invalid.', 'formidable' );
@@ -411,8 +450,9 @@
411 450 *
412 451 * @since 6.3.1
413 452 *
414 453 * @param array|string $event Uses 'create' or 'update'.
454 + *
415 455 * @return object
416 456 */
417 457 public static function get_fallback_action_after_open_in_new_tab( $event ) {
418 458 $action = self::get_fallback_action( $event );
@@ -425,8 +465,10 @@
425 465 /**
426 466 * Check if the current event has been passed. If not, use create actions.
427 467 *
428 468 * @since 6.1.1
469 + *
470 + * @param array $atts
429 471 *
430 472 * @return string
431 473 */
432 474 public static function current_event( $atts ) {