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/FrmSubmitHelper.php +26 -4 6.25.1 → trunk View file →
@@ -2,8 +2,9 @@
2 2 /**
3 3 * Submit helper
4 4 *
5 5 * @since 6.9
6 + *
6 7 * @package Formidable
7 8 */
8 9
9 10 if ( ! defined( 'ABSPATH' ) ) {
@@ -39,8 +40,9 @@
39 40 /**
40 41 * Gets submit field object.
41 42 *
42 43 * @param int $form_id Form ID.
44 + *
43 45 * @return object
44 46 */
45 47 public static function get_submit_field( $form_id ) {
46 48 return FrmField::get_all_types_in_form( $form_id, self::FIELD_TYPE, 1 );
@@ -49,8 +51,9 @@
49 51 /**
50 52 * Checks if there is submit button field on the current page.
51 53 *
52 54 * @param array $values Prepared form values.
55 + *
53 56 * @return bool
54 57 */
55 58 public static function has_submit_field_on_current_page( $values ) {
56 59 if ( empty( $values['fields'] ) ) {
@@ -63,8 +66,9 @@
63 66 /**
64 67 * Checks if the given fields list contains a submit field.
65 68 *
66 69 * @param array $fields Array of fields.
70 + *
67 71 * @return bool
68 72 */
69 73 private static function has_submit_field_in_list( $fields ) {
70 74 foreach ( $fields as $field ) {
@@ -79,13 +83,13 @@
79 83 /**
80 84 * Gets current action (create or update) from the global variable.
81 85 *
82 86 * @param int $form_id Form ID.
87 + *
83 88 * @return string
84 89 */
85 90 public static function get_current_action_from_global_var( $form_id ) {
86 91 global $frm_vars;
87 -
88 92 return $frm_vars['form_params'][ $form_id ]['action'] ?? 'create';
89 93 }
90 94
91 95 /**
@@ -91,8 +95,9 @@
91 95 /**
92 96 * Gets submit button settings from form option.
93 97 *
94 98 * @param object $form Form object.
99 + *
95 100 * @return array
96 101 */
97 102 private static function get_submit_settings_from_form( $form ) {
98 103 return array(
@@ -126,12 +131,14 @@
126 131 /**
127 132 * Copies submit field settings to form options.
128 133 *
129 134 * @param object $form Form object.
135 + *
130 136 * @return object
131 137 */
132 138 public static function copy_submit_field_settings_to_form( $form ) {
133 139 $submit_field = self::get_submit_field( $form->id );
140 +
134 141 if ( ! $submit_field ) {
135 142 return $form;
136 143 }
137 144
@@ -145,8 +152,10 @@
145 152 *
146 153 * @param object $form Form object.
147 154 * @param array $fields Array of fields.
148 155 * @param bool $reset_fields Flag to refresh fields after one is created or updated.
156 + *
157 + * @return void
149 158 */
150 159 public static function maybe_create_submit_field( $form, $fields, &$reset_fields ) {
151 160 if ( self::has_submit_field_in_list( $fields ) ) {
152 161 return;
@@ -151,10 +160,9 @@
151 160 if ( self::has_submit_field_in_list( $fields ) ) {
152 161 return;
153 162 }
154 163
155 - $field_data = FrmFieldsHelper::setup_new_vars( self::FIELD_TYPE, $form->id );
156 -
164 + $field_data = FrmFieldsHelper::setup_new_vars( self::FIELD_TYPE, $form->id );
157 165 $submit_settings = self::get_submit_settings_from_form( $form );
158 166 $field_data['field_options'] = $submit_settings + $field_data['field_options'];
159 167 $field_data['name'] = FrmForm::get_option(
160 168 array(
@@ -172,8 +180,10 @@
172 180 /**
173 181 * Removes submit field from the list of fields.
174 182 *
175 183 * @param array $fields Array of fields.
184 + *
185 + * @return void
176 186 */
177 187 public static function remove_submit_field_from_list( &$fields ) {
178 188 foreach ( $fields as $key => $field ) {
179 189 if ( self::FIELD_TYPE === FrmField::get_field_type( $field ) ) {
@@ -186,18 +196,22 @@
186 196 /**
187 197 * Checks if the given fields array only contains the submit field.
188 198 *
189 199 * @param array $fields Array of fields.
200 + *
190 201 * @return false|object Return the last found submit field, or `false` if there is at least another field.
191 202 */
192 203 public static function only_contains_submit_field( $fields ) {
193 204 $submit_field = false;
205 +
194 206 foreach ( $fields as $field ) {
195 207 if ( self::FIELD_TYPE !== FrmField::get_field_type( $field ) ) {
196 208 return false;
197 209 }
210 +
198 211 $submit_field = $field;
199 212 }
213 +
200 214 return $submit_field;
201 215 }
202 216
203 217 /**
@@ -205,16 +219,21 @@
205 219 *
206 220 * @since 6.25.1
207 221 *
208 222 * @param int $field_count The current field count.
223 + *
224 + * @return void
209 225 */
210 226 public static function update_last_row_fields_order_when_adding_field( $field_count ) {
211 227 $last_row_field_ids = FrmAppHelper::get_post_param( 'last_row_field_ids', array() );
212 - if ( ! is_array( $last_row_field_ids ) || empty( $last_row_field_ids ) ) {
228 +
229 + if ( ! is_array( $last_row_field_ids ) || ! $last_row_field_ids ) {
213 230 return;
214 231 }
232 +
215 233 foreach ( $last_row_field_ids as $index => $last_row_field_id ) {
216 234 $last_row_field_id = absint( $last_row_field_id );
235 +
217 236 if ( ! $last_row_field_id ) {
218 237 continue;
219 238 }
220 239 // Plus 2 here because the new field has that plus 1.
@@ -222,8 +241,9 @@
222 241 $updated = FrmField::update(
223 242 $last_row_field_id,
224 243 array( 'field_order' => $new_order )
225 244 );
245 +
226 246 if ( false !== $updated ) {
227 247 self::$last_row_fields_order[ $last_row_field_id ] = $new_order;
228 248 }
229 249 }
@@ -232,8 +252,10 @@
232 252 /**
233 253 * Prints the hidden input that contains the last row fields order to be processed in JS after adding new field.
234 254 *
235 255 * @since 6.25.1
256 + *
257 + * @return void
236 258 */
237 259 public static function print_last_row_fields_order_input() {
238 260 if ( ! self::$last_row_fields_order ) {
239 261 return;