PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.12
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.12
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 +8 -87 6.296.12 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,14 +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 - return $frm_vars['form_params'][ $form_id ]['action'] ?? 'create';
73 +
74 + if ( isset( $frm_vars['form_params'][ $form_id ]['action'] ) ) {
75 + return $frm_vars['form_params'][ $form_id ]['action'];
76 + }
77 +
78 + return 'create';
93 79 }
94 80
95 81 /**
96 82 * Gets submit button settings from form option.
@@ -95,9 +81,8 @@
95 81 /**
96 82 * Gets submit button settings from form option.
97 83 *
98 84 * @param object $form Form object.
99 - *
100 85 * @return array
101 86 */
102 87 private static function get_submit_settings_from_form( $form ) {
103 88 return array(
@@ -131,14 +116,12 @@
131 116 /**
132 117 * Copies submit field settings to form options.
133 118 *
134 119 * @param object $form Form object.
135 - *
136 120 * @return object
137 121 */
138 122 public static function copy_submit_field_settings_to_form( $form ) {
139 123 $submit_field = self::get_submit_field( $form->id );
140 -
141 124 if ( ! $submit_field ) {
142 125 return $form;
143 126 }
144 127
@@ -152,10 +135,8 @@
152 135 *
153 136 * @param object $form Form object.
154 137 * @param array $fields Array of fields.
155 138 * @param bool $reset_fields Flag to refresh fields after one is created or updated.
156 - *
157 - * @return void
158 139 */
159 140 public static function maybe_create_submit_field( $form, $fields, &$reset_fields ) {
160 141 if ( self::has_submit_field_in_list( $fields ) ) {
161 142 return;
@@ -160,9 +141,10 @@
160 141 if ( self::has_submit_field_in_list( $fields ) ) {
161 142 return;
162 143 }
163 144
164 - $field_data = FrmFieldsHelper::setup_new_vars( self::FIELD_TYPE, $form->id );
145 + $field_data = FrmFieldsHelper::setup_new_vars( self::FIELD_TYPE, $form->id );
146 +
165 147 $submit_settings = self::get_submit_settings_from_form( $form );
166 148 $field_data['field_options'] = $submit_settings + $field_data['field_options'];
167 149 $field_data['name'] = FrmForm::get_option(
168 150 array(
@@ -180,10 +162,8 @@
180 162 /**
181 163 * Removes submit field from the list of fields.
182 164 *
183 165 * @param array $fields Array of fields.
184 - *
185 - * @return void
186 166 */
187 167 public static function remove_submit_field_from_list( &$fields ) {
188 168 foreach ( $fields as $key => $field ) {
189 169 if ( self::FIELD_TYPE === FrmField::get_field_type( $field ) ) {
@@ -196,76 +176,17 @@
196 176 /**
197 177 * Checks if the given fields array only contains the submit field.
198 178 *
199 179 * @param array $fields Array of fields.
200 - *
201 180 * @return false|object Return the last found submit field, or `false` if there is at least another field.
202 181 */
203 182 public static function only_contains_submit_field( $fields ) {
204 183 $submit_field = false;
205 -
206 184 foreach ( $fields as $field ) {
207 185 if ( self::FIELD_TYPE !== FrmField::get_field_type( $field ) ) {
208 186 return false;
209 187 }
210 -
211 188 $submit_field = $field;
212 189 }
213 -
214 190 return $submit_field;
215 - }
216 -
217 - /**
218 - * Updates fields in the last row when new field is added.
219 - *
220 - * @since 6.25.1
221 - *
222 - * @param int $field_count The current field count.
223 - *
224 - * @return void
225 - */
226 - public static function update_last_row_fields_order_when_adding_field( $field_count ) {
227 - $last_row_field_ids = FrmAppHelper::get_post_param( 'last_row_field_ids', array() );
228 -
229 - if ( ! is_array( $last_row_field_ids ) || ! $last_row_field_ids ) {
230 - return;
231 - }
232 -
233 - foreach ( $last_row_field_ids as $index => $last_row_field_id ) {
234 - $last_row_field_id = absint( $last_row_field_id );
235 -
236 - if ( ! $last_row_field_id ) {
237 - continue;
238 - }
239 - // Plus 2 here because the new field has that plus 1.
240 - $new_order = $field_count + $index + 2;
241 - $updated = FrmField::update(
242 - $last_row_field_id,
243 - array( 'field_order' => $new_order )
244 - );
245 -
246 - if ( false !== $updated ) {
247 - self::$last_row_fields_order[ $last_row_field_id ] = $new_order;
248 - }
249 - }
250 - }
251 -
252 - /**
253 - * Prints the hidden input that contains the last row fields order to be processed in JS after adding new field.
254 - *
255 - * @since 6.25.1
256 - *
257 - * @return void
258 - */
259 - public static function print_last_row_fields_order_input() {
260 - if ( ! self::$last_row_fields_order ) {
261 - return;
262 - }
263 -
264 - printf(
265 - '<input id="frm-last-row-fields-order" type="hidden" value="%s" />',
266 - esc_attr( wp_json_encode( self::$last_row_fields_order ) )
267 - );
268 -
269 - self::$last_row_fields_order = array();
270 191 }
271 192 }