PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 1.2.4
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v1.2.4
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 3.6.66 All 195 releases
fluentform / app / Modules / Form / FormDataParser.php

FormDataParser.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 1.2.4, at app/Modules/Form/FormDataParser.php

72 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentForm\App\Modules\Form;
4
5 class FormDataParser
6 {
7 protected static $data = null;
8
9 public static function parseFormEntries($entries, $form, $fields = null)
10 {
11 $fields = $fields ? $fields : FormFieldsParser::getEntryInputs($form);
12
13 foreach ($entries as $entry) {
14 static::parseFormEntry($entry, $form, $fields);
15 }
16
17 return $entries;
18 }
19
20 public static function parseFormEntry($entry, $form, $fields = null)
21 {
22 $fields = $fields ? $fields : FormFieldsParser::getEntryInputs($form);
23
24 $entry->user_inputs = static::parseData(
25 json_decode($entry->response), $fields, $form->id
26 );
27
28 return $entry;
29 }
30
31 public static function parseFormSubmission($submition, $form, $fields)
32 {
33 if (is_null(static::$data)) {
34 static::$data = static::parseData(
35 json_decode($submition->response), $fields, $form->id
36 );
37 }
38 $submission->user_inputs = static::$data;
39
40 return $submission;
41 }
42
43 public static function parseData($response, $fields, $formId)
44 {
45 $trans = [];
46 foreach ($fields as $field_key => $field) {
47 if (isset($response->$field_key)) {
48 $value = apply_filters(
49 'fluentform_response_render_'.$field['element'],
50 $response->$field_key,
51 $field,
52 $formId
53 );
54 $trans[$field_key] = $value;
55 } else {
56 $trans[$field_key] = null;
57 }
58 }
59
60 return $trans;
61 }
62
63 public static function formatValue($value)
64 {
65 if (is_array($value) || is_object($value)) {
66 return implodeRecursive(', ', array_filter(array_values((array) $value)));
67 }
68
69 return $value;
70 }
71 }
72