PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.19
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.19
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 -80 6.356.19 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' ) ) {
@@ -30,19 +29,11 @@
30 29 */
31 30 const DEFAULT_ORDER = 9999;
32 31
33 32 /**
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 33 * Gets submit field object.
42 34 *
43 35 * @param int $form_id Form ID.
44 - *
45 36 * @return object
46 37 */
47 38 public static function get_submit_field( $form_id ) {
48 39 return FrmField::get_all_types_in_form( $form_id, self::FIELD_TYPE, 1 );
@@ -51,9 +42,8 @@
51 42 /**
52 43 * Checks if there is submit button field on the current page.
53 44 *
54 45 * @param array $values Prepared form values.
55 - *
56 46 * @return bool
57 47 */
58 48 public static function has_submit_field_on_current_page( $values ) {
59 49 if ( empty( $values['fields'] ) ) {
@@ -66,9 +56,8 @@
66 56 /**
67 57 * Checks if the given fields list contains a submit field.
68 58 *
69 59 * @param array $fields Array of fields.
70 - *
71 60 * @return bool
72 61 */
73 62 private static function has_submit_field_in_list( $fields ) {
74 63 foreach ( $fields as $field ) {
@@ -83,14 +72,18 @@
83 72 /**
84 73 * Gets current action (create or update) from the global variable.
85 74 *
86 75 * @param int $form_id Form ID.
87 - *
88 76 * @return string
89 77 */
90 78 public static function get_current_action_from_global_var( $form_id ) {
91 79 global $frm_vars;
92 - return $frm_vars['form_params'][ $form_id ]['action'] ?? 'create';
80 +
81 + if ( isset( $frm_vars['form_params'][ $form_id ]['action'] ) ) {
82 + return $frm_vars['form_params'][ $form_id ]['action'];
83 + }
84 +
85 + return 'create';
93 86 }
94 87
95 88 /**
96 89 * Gets submit button settings from form option.
@@ -95,9 +88,8 @@
95 88 /**
96 89 * Gets submit button settings from form option.
97 90 *
98 91 * @param object $form Form object.
99 - *
100 92 * @return array
101 93 */
102 94 private static function get_submit_settings_from_form( $form ) {
103 95 return array(
@@ -131,14 +123,12 @@
131 123 /**
132 124 * Copies submit field settings to form options.
133 125 *
134 126 * @param object $form Form object.
135 - *
136 127 * @return object
137 128 */
138 129 public static function copy_submit_field_settings_to_form( $form ) {
139 130 $submit_field = self::get_submit_field( $form->id );
140 -
141 131 if ( ! $submit_field ) {
142 132 return $form;
143 133 }
144 134
@@ -152,10 +142,8 @@
152 142 *
153 143 * @param object $form Form object.
154 144 * @param array $fields Array of fields.
155 145 * @param bool $reset_fields Flag to refresh fields after one is created or updated.
156 - *
157 - * @return void
158 146 */
159 147 public static function maybe_create_submit_field( $form, $fields, &$reset_fields ) {
160 148 if ( self::has_submit_field_in_list( $fields ) ) {
161 149 return;
@@ -160,9 +148,10 @@
160 148 if ( self::has_submit_field_in_list( $fields ) ) {
161 149 return;
162 150 }
163 151
164 - $field_data = FrmFieldsHelper::setup_new_vars( self::FIELD_TYPE, $form->id );
152 + $field_data = FrmFieldsHelper::setup_new_vars( self::FIELD_TYPE, $form->id );
153 +
165 154 $submit_settings = self::get_submit_settings_from_form( $form );
166 155 $field_data['field_options'] = $submit_settings + $field_data['field_options'];
167 156 $field_data['name'] = FrmForm::get_option(
168 157 array(
@@ -180,10 +169,8 @@
180 169 /**
181 170 * Removes submit field from the list of fields.
182 171 *
183 172 * @param array $fields Array of fields.
184 - *
185 - * @return void
186 173 */
187 174 public static function remove_submit_field_from_list( &$fields ) {
188 175 foreach ( $fields as $key => $field ) {
189 176 if ( self::FIELD_TYPE === FrmField::get_field_type( $field ) ) {
@@ -196,76 +183,17 @@
196 183 /**
197 184 * Checks if the given fields array only contains the submit field.
198 185 *
199 186 * @param array $fields Array of fields.
200 - *
201 187 * @return false|object Return the last found submit field, or `false` if there is at least another field.
202 188 */
203 189 public static function only_contains_submit_field( $fields ) {
204 190 $submit_field = false;
205 -
206 191 foreach ( $fields as $field ) {
207 192 if ( self::FIELD_TYPE !== FrmField::get_field_type( $field ) ) {
208 193 return false;
209 194 }
210 -
211 195 $submit_field = $field;
212 196 }
213 -
214 197 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 198 }
271 199 }