PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.13
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.13
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/FrmSubmitHelper.php +5 -85 6.266.13 View file →
@@ -2,9 +2,8 @@
2 2 /**
3 3 * Submit helper
4 4 *
5 5 * @since 6.9
6 - *
7 6 * @package Formidable
8 7 */
9 8
10 9 if ( ! defined( 'ABSPATH' ) ) {
@@ -23,26 +22,11 @@
23 22 */
24 23 const FIELD_TYPE = 'submit';
25 24
26 25 /**
27 - * Default order for submit field.
28 - *
29 - * @var int
30 - */
31 - const DEFAULT_ORDER = 9999;
32 -
33 - /**
34 - * Track the new order of last row fields after a new field is added.
35 - *
36 - * @var array Keys are field IDs, values are the order.
37 - */
38 - private static $last_row_fields_order = array();
39 -
40 - /**
41 26 * Gets submit field object.
42 27 *
43 28 * @param int $form_id Form ID.
44 - *
45 29 * @return object
46 30 */
47 31 public static function get_submit_field( $form_id ) {
48 32 return FrmField::get_all_types_in_form( $form_id, self::FIELD_TYPE, 1 );
@@ -51,9 +35,8 @@
51 35 /**
52 36 * Checks if there is submit button field on the current page.
53 37 *
54 38 * @param array $values Prepared form values.
55 - *
56 39 * @return bool
57 40 */
58 41 public static function has_submit_field_on_current_page( $values ) {
59 42 if ( empty( $values['fields'] ) ) {
@@ -66,9 +49,8 @@
66 49 /**
67 50 * Checks if the given fields list contains a submit field.
68 51 *
69 52 * @param array $fields Array of fields.
70 - *
71 53 * @return bool
72 54 */
73 55 private static function has_submit_field_in_list( $fields ) {
74 56 foreach ( $fields as $field ) {
@@ -83,15 +65,18 @@
83 65 /**
84 66 * Gets current action (create or update) from the global variable.
85 67 *
86 68 * @param int $form_id Form ID.
87 - *
88 69 * @return string
89 70 */
90 71 public static function get_current_action_from_global_var( $form_id ) {
91 72 global $frm_vars;
92 73
93 - return $frm_vars['form_params'][ $form_id ]['action'] ?? 'create';
74 + if ( isset( $frm_vars['form_params'][ $form_id ]['action'] ) ) {
75 + return $frm_vars['form_params'][ $form_id ]['action'];
76 + }
77 +
78 + return 'create';
94 79 }
95 80
96 81 /**
97 82 * Gets submit button settings from form option.
@@ -96,9 +81,8 @@
96 81 /**
97 82 * Gets submit button settings from form option.
98 83 *
99 84 * @param object $form Form object.
100 - *
101 85 * @return array
102 86 */
103 87 private static function get_submit_settings_from_form( $form ) {
104 88 return array(
@@ -132,14 +116,12 @@
132 116 /**
133 117 * Copies submit field settings to form options.
134 118 *
135 119 * @param object $form Form object.
136 - *
137 120 * @return object
138 121 */
139 122 public static function copy_submit_field_settings_to_form( $form ) {
140 123 $submit_field = self::get_submit_field( $form->id );
141 -
142 124 if ( ! $submit_field ) {
143 125 return $form;
144 126 }
145 127
@@ -153,10 +135,8 @@
153 135 *
154 136 * @param object $form Form object.
155 137 * @param array $fields Array of fields.
156 138 * @param bool $reset_fields Flag to refresh fields after one is created or updated.
157 - *
158 - * @return void
159 139 */
160 140 public static function maybe_create_submit_field( $form, $fields, &$reset_fields ) {
161 141 if ( self::has_submit_field_in_list( $fields ) ) {
162 142 return;
@@ -182,10 +162,8 @@
182 162 /**
183 163 * Removes submit field from the list of fields.
184 164 *
185 165 * @param array $fields Array of fields.
186 - *
187 - * @return void
188 166 */
189 167 public static function remove_submit_field_from_list( &$fields ) {
190 168 foreach ( $fields as $key => $field ) {
191 169 if ( self::FIELD_TYPE === FrmField::get_field_type( $field ) ) {
@@ -198,75 +176,17 @@
198 176 /**
199 177 * Checks if the given fields array only contains the submit field.
200 178 *
201 179 * @param array $fields Array of fields.
202 - *
203 180 * @return false|object Return the last found submit field, or `false` if there is at least another field.
204 181 */
205 182 public static function only_contains_submit_field( $fields ) {
206 183 $submit_field = false;
207 -
208 184 foreach ( $fields as $field ) {
209 185 if ( self::FIELD_TYPE !== FrmField::get_field_type( $field ) ) {
210 186 return false;
211 187 }
212 -
213 188 $submit_field = $field;
214 189 }
215 190 return $submit_field;
216 - }
217 -
218 - /**
219 - * Updates fields in the last row when new field is added.
220 - *
221 - * @since 6.25.1
222 - *
223 - * @param int $field_count The current field count.
224 - *
225 - * @return void
226 - */
227 - public static function update_last_row_fields_order_when_adding_field( $field_count ) {
228 - $last_row_field_ids = FrmAppHelper::get_post_param( 'last_row_field_ids', array() );
229 -
230 - if ( ! is_array( $last_row_field_ids ) || empty( $last_row_field_ids ) ) {
231 - return;
232 - }
233 -
234 - foreach ( $last_row_field_ids as $index => $last_row_field_id ) {
235 - $last_row_field_id = absint( $last_row_field_id );
236 -
237 - if ( ! $last_row_field_id ) {
238 - continue;
239 - }
240 - // Plus 2 here because the new field has that plus 1.
241 - $new_order = $field_count + $index + 2;
242 - $updated = FrmField::update(
243 - $last_row_field_id,
244 - array( 'field_order' => $new_order )
245 - );
246 -
247 - if ( false !== $updated ) {
248 - self::$last_row_fields_order[ $last_row_field_id ] = $new_order;
249 - }
250 - }
251 - }
252 -
253 - /**
254 - * Prints the hidden input that contains the last row fields order to be processed in JS after adding new field.
255 - *
256 - * @since 6.25.1
257 - *
258 - * @return void
259 - */
260 - public static function print_last_row_fields_order_input() {
261 - if ( ! self::$last_row_fields_order ) {
262 - return;
263 - }
264 -
265 - printf(
266 - '<input id="frm-last-row-fields-order" type="hidden" value="%s" />',
267 - esc_attr( wp_json_encode( self::$last_row_fields_order ) )
268 - );
269 -
270 - self::$last_row_fields_order = array();
271 191 }
272 192 }