PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.14
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.14
6.2.14 6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 All 196 releases
← All changes | app/Services/Parser/Form.php +136 -31 3.6.656.2.14 View file →
@@ -24,8 +24,15 @@
24 24 */
25 25 protected $parsed;
26 26
27 27 /**
28 + * The parsed essential form fields.
29 + *
30 + * @var array
31 + */
32 + protected $essentials;
33 +
34 + /**
28 35 * The parsed validations
29 36 *
30 37 * @var array
31 38 */
@@ -45,9 +52,9 @@
45 52
46 53 /**
47 54 * Set input types of the form.
48 55 *
49 - * @param array $types
56 + * @param array $types
50 57 * @return \FluentForm\App\Services\Parser\Form $this
51 58 */
52 59 public function setInputTypes($types = [])
53 60 {
@@ -76,11 +83,20 @@
76 83 'tabular_grid',
77 84 'gdpr_agreement',
78 85 'taxonomy'
79 86 ];
80 -
87 +
88 + $types = apply_filters_deprecated(
89 + 'fluentform_form_input_types',
90 + [
91 + $types
92 + ],
93 + FLUENTFORM_FRAMEWORK_UPGRADE,
94 + 'fluentform/form_input_types',
95 + 'Use fluentform/form_input_types instead of fluentform_form_input_types'
96 + );
81 97 // Firing an event so that others can hook into it and add other input types.
82 - $this->inputTypes = apply_filters('fluentform_form_input_types', $types);
98 + $this->inputTypes = apply_filters('fluentform/form_input_types', $types);
83 99
84 100 return $this;
85 101 }
86 102
@@ -86,18 +102,23 @@
86 102
87 103 /**
88 104 * Get form fields.
89 105 *
90 - * @param boolean $asArray
106 + * @param boolean $asArray
91 107 * @return array
92 108 */
93 109 public function getFields($asArray = false)
94 110 {
111 + $default = $asArray ? [] : null;
112 +
113 + // Return default if form_fields is null or empty
114 + if (!$this->form || !isset($this->form->form_fields) || $this->form->form_fields === null) {
115 + return $default;
116 + }
117 +
95 118 $fields = json_decode($this->form->form_fields, $asArray);
96 119
97 - $default = $asArray ? [] : null;
98 -
99 - return Arr::get((array) $fields, 'fields', $default);
120 + return Arr::get((array)$fields, 'fields', $default);
100 121 }
101 122
102 123 /**
103 124 * Get flatten form inputs. Flatten implies that all
@@ -102,9 +123,9 @@
102 123 /**
103 124 * Get flatten form inputs. Flatten implies that all
104 125 * of the form fields will be in a simple array.
105 126 *
106 - * @param array $with
127 + * @param array $with
107 128 * @return array
108 129 */
109 130 public function getInputs($with = [])
110 131 {
@@ -123,9 +144,9 @@
123 144 /**
124 145 * Get the inputs just as they setup in the form editor.
125 146 * e.g. `names` as `names` not with the child fields.
126 147 *
127 - * @param array $with
148 + * @param array $with
128 149 * @return array
129 150 */
130 151 public function getEntryInputs($with = ['admin_label'])
131 152 {
@@ -174,9 +195,9 @@
174 195
175 196 /**
176 197 * Get admin labels of the form fields.
177 198 *
178 - * @param array $fields
199 + * @param array $fields
179 200 * @return array
180 201 */
181 202 public function getAdminLabels($fields = [])
182 203 {
@@ -193,10 +214,10 @@
193 214
194 215 /**
195 216 * Get admin labels of the form fields.
196 217 *
197 - * @param array $inputs
198 - * @param array $fields
218 + * @param array $inputs
219 + * @param array $fields
199 220 * @return array
200 221 */
201 222 public function getValidations($inputs, $fields = [])
202 223 {
@@ -213,10 +234,10 @@
213 234
214 235 /**
215 236 * Get an element by it's name.
216 237 *
217 - * @param string|array $name
218 - * @param array $with
238 + * @param string|array $name
239 + * @param array $with
219 240 * @return array
220 241 */
221 242 public function getElement($name, $with = [])
222 243 {
@@ -227,20 +248,28 @@
227 248
228 249 /**
229 250 * Determine whether the form has an element.
230 251 *
231 - * @param string $name
252 + * @param string $name
232 253 * @return bool
233 254 */
234 255 public function hasElement($name)
235 256 {
236 - return array_key_exists($name, $this->getElement($name, ['element']));
257 + $elements = $this->getElement($name, ['element']);
258 +
259 + foreach ($elements as $item) {
260 + if ($item['element'] === $name) {
261 + return true;
262 + }
263 + }
264 +
265 + return false;
237 266 }
238 267
239 268 /**
240 269 * Determine whether the form has any required fields.
241 270 *
242 - * @param array $fields
271 + * @param array $fields
243 272 * @return bool
244 273 */
245 274 public function hasRequiredFields($fields = [])
246 275 {
@@ -258,9 +287,9 @@
258 287 break;
259 288 }
260 289 }
261 290
262 - return (boolean) $exist;
291 + return (bool) $exist;
263 292 }
264 293
265 294
266 295 /**
@@ -268,20 +297,36 @@
268 297 *
269 298 * @param array $with array
270 299 * @return array
271 300 */
272 - public function getPaymentFields($with = ['element'])
301 + public function getPaymentFields($with = ['element', 'settings'])
273 302 {
274 303 $fields = $this->getInputs($with);
275 - $paymentElements = [
276 - 'custom_payment_component',
277 - 'multi_payment_component',
278 - 'payment_method',
279 - 'item_quantity_component',
280 - 'payment_coupon'
304 +
305 + $data = [
306 + 'custom_payment_component',
307 + 'multi_payment_component',
308 + 'payment_method',
309 + 'item_quantity_component',
310 + 'rangeslider',
311 + 'payment_coupon',
312 + 'subscription_payment_component',
281 313 ];
314 +
315 + $data = apply_filters_deprecated('fluentform_form_payment_fields', [
316 + $data
317 + ],
318 + FLUENTFORM_FRAMEWORK_UPGRADE,
319 + 'fluentform/form_payment_fields',
320 + 'Use fluentform/form_payment_fields instead of fluentform_form_payment_fields'
321 + );
282 322
323 + $paymentElements = apply_filters('fluentform/form_payment_fields', $data);
324 +
283 325 return array_filter($fields, function ($field) use ($paymentElements) {
326 + if ($field['element'] === 'rangeslider') {
327 + return Arr::get($field, 'settings.enable_target_product', 'no') === 'yes';
328 + }
284 329 return in_array($field['element'], $paymentElements);
285 330 });
286 331 }
287 332
@@ -292,13 +337,26 @@
292 337 */
293 338 public function getPaymentInputFields($with = ['element'])
294 339 {
295 340 $fields = $this->getInputs($with);
296 - $paymentElements = [
341 +
342 + $data = [
297 343 'custom_payment_component',
298 344 'multi_payment_component'
299 345 ];
346 +
347 + $data = apply_filters_deprecated(
348 + 'fluentform_form_payment_inputs',
349 + [
350 + $data
351 + ],
352 + FLUENTFORM_FRAMEWORK_UPGRADE,
353 + 'fluentform/form_payment_inputs',
354 + 'Use fluentform/form_payment_inputs instead of fluentform_form_payment_inputs'
355 + );
300 356
357 + $paymentElements = apply_filters('fluentform/form_payment_inputs', $data);
358 +
301 359 return array_filter($fields, function ($field) use ($paymentElements) {
302 360 return in_array($field['element'], $paymentElements);
303 361 });
304 362 }
@@ -311,15 +369,31 @@
311 369 public function hasPaymentFields()
312 370 {
313 371 $fields = $this->getInputs(['element']);
314 372
315 - $paymentElements = [
373 + $data = [
316 374 'custom_payment_component',
317 375 'multi_payment_component',
318 - 'payment_method'
376 + 'payment_method',
377 + 'item_quantity_component',
378 + 'payment_coupon',
379 + 'subscription_payment_component'
319 380 ];
381 +
382 + $data = apply_filters_deprecated(
383 + 'fluentform_form_payment_fields',
384 + [
385 + $data
386 + ],
387 + FLUENTFORM_FRAMEWORK_UPGRADE,
388 + 'fluentform/form_payment_fields',
389 + 'Use fluentform/form_payment_fields instead of fluentform_form_payment_fields'
390 + );
391 +
392 + $paymentElements = apply_filters('fluentform/form_payment_fields', $data);
393 +
320 394 foreach ($fields as $field) {
321 - if(in_array($field['element'], $paymentElements)) {
395 + if (in_array($field['element'], $paymentElements)) {
322 396 return true;
323 397 }
324 398 }
325 399
@@ -331,9 +405,9 @@
331 405 * Get an specific field for an element type.
332 406 *
333 407 * @param $element
334 408 * @param $attribute
335 - * @param array $with
409 + * @param array $with
336 410 * @return array|null
337 411 */
338 412 public function getField($element, $attribute, $with = [])
339 413 {
@@ -338,9 +412,9 @@
338 412 public function getField($element, $attribute, $with = [])
339 413 {
340 414 $element = $this->getElement($element, $with);
341 415
342 - return array_intersect_key($element, array_flip((array) $attribute));
416 + return array_intersect_key($element, array_flip((array)$attribute));
343 417 }
344 418
345 419
346 420 /**
@@ -376,5 +450,36 @@
376 450 return in_array($field['element'], $types);
377 451 });
378 452 }
379 453
454 + /**
455 + * Get Address Fields
456 + *
457 + * @return array
458 + */
459 + public function getAddressFields($with = ['admin_label', 'attributes'])
460 + {
461 + $fields = $this->getInputs($with);
462 + $addressElements = [
463 + 'address'
464 + ];
465 +
466 + return array_filter($fields, function ($field) use ($addressElements) {
467 + return in_array($field['element'], $addressElements);
468 + });
469 + }
470 +
471 + public function getEssentialInputs($formData, $with = [])
472 + {
473 + // If the form is already parsed we'll return it. Otherwise,
474 + // we'll parse the form and return the data after saving it.
475 + if (!$this->essentials) {
476 + $fields = $this->getFields(true);
477 +
478 + $with = $with ?: ['rules', 'raw'];
479 +
480 + $this->essentials = (new Extractor($fields, $with, $this->inputTypes))->extractEssentials($formData);
481 + }
482 +
483 + return $this->essentials;
484 + }
380 485 }