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/Form/SubmissionHandlerService.php +89 -48 6.2.56.2.14 View file →
@@ -34,8 +34,9 @@
34 34 }
35 35
36 36 /**
37 37 * Form Submission
38 + *
38 39 * @param $formDataRaw
39 40 * @param $formId
40 41 * @return array
41 42 * @throws \FluentForm\Framework\Validator\ValidationException
@@ -52,8 +53,10 @@
52 53 return $this->processSubmissionData($insertId, $this->formData, $this->form);
53 54 }
54 55
55 56 /**
57 + * Prepare the form and validated form data for submission handling.
58 + *
56 59 * @throws ValidationException
57 60 */
58 61 protected function prepareHandler($formId, $formDataRaw)
59 62 {
@@ -71,32 +74,19 @@
71 74 */
72 75 foreach ($formDataRaw as $name => $input) {
73 76 if (is_array($input)) {
74 77 $formDataRaw[$name] = array_filter($input, function ($value) {
75 - return $value !== null && $value !== false && $value !== '';
78 + return null !== $value && false !== $value && '' !== $value;
76 79 });
77 80 }
78 81
79 - // Process "Other" options for checkboxes and radio fields
80 - if (strpos($name, '__ff_other_input__') !== false && !empty($input)) {
82 + // Resolve a checkbox/radio "Other" selection once its free text is known.
83 + if (strpos($name, '__ff_other_input__') !== false) {
81 84 $fieldName = str_replace('__ff_other_input__', '', $name);
82 85
83 - // Handle checkbox fields (array values)
84 - if (isset($formDataRaw[$fieldName]) && is_array($formDataRaw[$fieldName])) {
85 - $selectedValues = $formDataRaw[$fieldName];
86 -
87 - // Handle field-specific "Other" values
88 - $otherValue = '__ff_other_' . $fieldName . '__';
89 -
90 - $key = array_search($otherValue, $selectedValues);
91 -
92 - if ($key !== false) {
93 - $selectedValues[$key] = 'Other: ' . sanitize_text_field($input);
94 - $formDataRaw[$fieldName] = $selectedValues;
95 - }
96 - } // Handle radio fields (single value)
97 - elseif (isset($formDataRaw[$fieldName]) && $formDataRaw[$fieldName] === '__ff_other_' . $fieldName . '__') {
98 - $formDataRaw[$fieldName] = 'Other: ' . sanitize_text_field($input);
86 + if (isset($formDataRaw[$fieldName])) {
87 + $otherText = is_scalar($input) ? trim((string) $input) : '';
88 + $formDataRaw[$fieldName] = $this->resolveOtherOption($formDataRaw[$fieldName], $fieldName, $otherText);
99 89 }
100 90
101 91 unset($formDataRaw[$name]);
102 92 }
@@ -120,11 +110,57 @@
120 110
121 111 $this->formData = array_intersect_key($formData, $acceptedFieldKeys);
122 112 }
123 113
114 + /**
115 + * Resolve a checkbox/radio "Other" selection now that its free text is known.
116 + *
117 + * Until here the field value carries the placeholder marker
118 + * `__ff_other_<field>__`. With text, swap the marker for the labelled answer
119 + * ("<Other label>: <text>"); without text, drop the marker so it never
120 + * reaches storage — and from there entry details, emails, PDFs and integrations.
121 + *
122 + * @param array|string $fieldValue checkbox array or radio string
123 + * @param string $fieldName
124 + * @param string $otherText trimmed free text typed for "Other"
125 + * @return array|string
126 + */
127 + protected function resolveOtherOption($fieldValue, $fieldName, $otherText)
128 + {
129 + $otherMarker = '__ff_other_' . $fieldName . '__';
130 + $otherText = trim($otherText);
124 131
132 + // Empty "Other": remove the marker.
133 + if ('' === $otherText) {
134 + if (is_array($fieldValue)) {
135 + return array_values(array_filter($fieldValue, function ($selectedValue) use ($otherMarker) {
136 + return $selectedValue !== $otherMarker;
137 + }));
138 + }
139 +
140 + return $fieldValue === $otherMarker ? '' : $fieldValue;
141 + }
142 +
143 + // Filled "Other": replace the marker with the labelled free text.
144 + $rawField = Arr::get(FormFieldsParser::getInputs($this->form, ['raw']), $fieldName . '.raw', []);
145 + $labelledAnswer = Helper::getOtherOptionValuePrefix($rawField, $this->form) . sanitize_text_field($otherText);
146 +
147 + if (is_array($fieldValue)) {
148 + $markerIndex = array_search($otherMarker, $fieldValue);
149 + if (false !== $markerIndex) {
150 + $fieldValue[$markerIndex] = $labelledAnswer;
151 + }
152 +
153 + return $fieldValue;
154 + }
155 +
156 + return $fieldValue === $otherMarker ? $labelledAnswer : $fieldValue;
157 + }
158 +
159 +
125 160 /**
126 161 * Prepare the data to be inserted to the database.
162 + *
127 163 * @param boolean $formData
128 164 * @return array
129 165 */
130 166 public function prepareInsertData($formData = false)
@@ -145,9 +181,9 @@
145 181 'fluentform_insert_response_data',
146 182 [
147 183 $formData,
148 184 $formId,
149 - $inputConfigs
185 + $inputConfigs,
150 186 ],
151 187 FLUENTFORM_FRAMEWORK_UPGRADE,
152 188 'fluentform/insert_response_data',
153 189 'Use fluentform/insert_response_data instead of fluentform_insert_response_data.'
@@ -159,9 +195,9 @@
159 195 $disableIpLog = apply_filters_deprecated(
160 196 'fluentform_disable_ip_logging',
161 197 [
162 198 false,
163 - $formId
199 + $formId,
164 200 ],
165 201 FLUENTFORM_FRAMEWORK_UPGRADE,
166 202 'fluentform/disable_ip_logging',
167 203 'Use fluentform/disable_ip_logging instead of fluentform_disable_ip_logging.'
@@ -174,9 +210,9 @@
174 210
175 211 $response = [
176 212 'form_id' => $formId,
177 213 'serial_number' => $serialNumber,
178 - 'response' => json_encode($this->formData, JSON_UNESCAPED_UNICODE),
214 + 'response' => wp_json_encode($this->formData, JSON_UNESCAPED_UNICODE),
179 215 'source_url' => site_url(Arr::get($formData, '_wp_http_referer')),
180 216 'user_id' => get_current_user_id(),
181 217 'browser' => $browser->getBrowser(),
182 218 'device' => $browser->getPlatform(),
@@ -188,9 +224,9 @@
188 224
189 225 $response = apply_filters_deprecated(
190 226 'fluentform_filter_insert_data',
191 227 [
192 - $response
228 + $response,
193 229 ],
194 230 FLUENTFORM_FRAMEWORK_UPGRADE,
195 231 'fluentform/filter_insert_data',
196 232 'Use fluentform/filter_insert_data instead of fluentform_filter_insert_data.'
@@ -204,12 +240,12 @@
204 240 $form = isset($this->form) ? $this->form : $form;
205 241 $formData = isset($this->formData) ? $this->formData : $formData;
206 242 do_action_deprecated(
207 243 'fluentform_before_form_actions_processing', [
208 - $insertId,
209 - $this->formData,
210 - $form
211 - ],
244 + $insertId,
245 + $this->formData,
246 + $form,
247 + ],
212 248 FLUENTFORM_FRAMEWORK_UPGRADE,
213 249 'fluentform/before_form_actions_processing',
214 250 'Use fluentform/before_form_actions_processing instead of fluentform_before_form_actions_processing.'
215 251 );
@@ -236,12 +272,12 @@
236 272 Helper::setSubmissionMeta($insertId, 'is_form_action_fired', 'yes');
237 273
238 274 do_action_deprecated(
239 275 'fluentform_submission_inserted_' . $form->type . '_form', [
240 - $insertId,
241 - $formData,
242 - $form
243 - ],
276 + $insertId,
277 + $formData,
278 + $form,
279 + ],
244 280 FLUENTFORM_FRAMEWORK_UPGRADE,
245 281 'fluentform/submission_inserted_' . $form->type . '_form',
246 282 'Use fluentform/submission_inserted_' . $form->type . '_form instead of fluentform_submission_inserted_' . $form->type . '_form'
247 283 );
@@ -260,12 +296,12 @@
260 296 }
261 297
262 298 do_action_deprecated(
263 299 'fluentform_before_submission_confirmation', [
264 - $insertId,
265 - $formData,
266 - $form
267 - ],
300 + $insertId,
301 + $formData,
302 + $form,
303 + ],
268 304 FLUENTFORM_FRAMEWORK_UPGRADE,
269 305 'fluentform/before_submission_confirmation',
270 306 'Use fluentform/before_submission_confirmation instead of fluentform_before_submission_confirmation.'
271 307 );
@@ -280,8 +316,9 @@
280 316 }
281 317
282 318 /**
283 319 * Return Formatted Response Data
320 + *
284 321 * @param $insertId
285 322 * @param $form
286 323 * @param $formData
287 324 * @return mixed
@@ -291,15 +328,19 @@
291 328 if (empty($form->settings)) {
292 329 $formSettings = FormMeta::retrieve('formSettings', $form->id);
293 330 $form->settings = is_array($formSettings) ? $formSettings : [];
294 331 }
295 - $confirmation = $form->settings['confirmation'];
332 + // A form written outside the editor may carry no confirmation block; the editor defaults apply
333 + $confirmation = Arr::get($form->settings, 'confirmation');
334 + if (!$confirmation) {
335 + $confirmation = Arr::get(Form::getFormsDefaultSettings(), 'confirmation', []);
336 + }
296 337 $confirmation = apply_filters_deprecated(
297 338 'fluentform_form_submission_confirmation',
298 339 [
299 340 $confirmation,
300 341 $formData,
301 - $form
342 + $form,
302 343 ],
303 344 FLUENTFORM_FRAMEWORK_UPGRADE,
304 345 'fluentform/form_submission_confirmation',
305 346 'Use fluentform/form_submission_confirmation instead of fluentform_form_submission_confirmation.'
@@ -312,9 +353,9 @@
312 353 $form
313 354 );
314 355 if ('samePage' == Arr::get($confirmation, 'redirectTo')) {
315 356
316 - $confirmation['messageToShow'] = fluentform_sanitize_html($confirmation['messageToShow']);
357 + $confirmation['messageToShow'] = fluentform_sanitize_html(Arr::get($confirmation, 'messageToShow', ''));
317 358
318 359 $confirmation['messageToShow'] = apply_filters_deprecated(
319 360 'fluentform_submission_message_parse',
320 361 [
@@ -320,9 +361,9 @@
320 361 [
321 362 $confirmation['messageToShow'],
322 363 $insertId,
323 364 $formData,
324 - $form
365 + $form,
325 366 ],
326 367 FLUENTFORM_FRAMEWORK_UPGRADE,
327 368 'fluentform/submission_message_parse',
328 369 'Use fluentform/submission_message_parse instead of fluentform_submission_message_parse.'
@@ -344,14 +385,14 @@
344 385 $message = $message ? $message : __('The form has been successfully submitted.', 'fluentform');
345 386
346 387 $returnData = [
347 388 'message' => $message,
348 - 'action' => $confirmation['samePageFormBehavior'],
389 + 'action' => Arr::get($confirmation, 'samePageFormBehavior', 'hide_form'),
349 390 ];
350 391 } else {
351 392 $redirectUrl = Arr::get($confirmation, 'customUrl');
352 - if ('customPage' == $confirmation['redirectTo']) {
353 - $redirectUrl = get_permalink($confirmation['customPage']);
393 + if ('customPage' === Arr::get($confirmation, 'redirectTo')) {
394 + $redirectUrl = get_permalink(Arr::get($confirmation, 'customPage'));
354 395 }
355 396 $enableQueryString = Arr::get($confirmation, 'enable_query_string') === 'yes';
356 397 $queryStrings = Arr::get($confirmation, 'query_strings');
357 398
@@ -360,9 +401,9 @@
360 401 $redirectUrl .= $separator . $queryStrings;
361 402 }
362 403 $parseUrl = apply_filters_deprecated('fluentform_will_parse_url_value', [
363 404 true,
364 - $form
405 + $form,
365 406 ],
366 407 FLUENTFORM_FRAMEWORK_UPGRADE,
367 408 'fluentform/will_parse_url_value',
368 409 'Use fluentform/will_parse_url_value instead of fluentform_will_parse_url_value.'
@@ -430,9 +471,9 @@
430 471 $returnData,
431 472 $form,
432 473 $confirmation,
433 474 $insertId,
434 - $formData
475 + $formData,
435 476 ],
436 477 FLUENTFORM_FRAMEWORK_UPGRADE,
437 478 'fluentform/submission_confirmation',
438 479 'Use fluentform/submission_confirmation instead of fluentform_submission_confirmation.'
@@ -511,8 +552,9 @@
511 552 }
512 553
513 554 /**
514 555 * Validates Submission
556 + *
515 557 * @throws ValidationException
516 558 */
517 559 private function handleValidation()
518 560 {
@@ -558,9 +600,9 @@
558 600 'fluentform_before_insert_submission',
559 601 [
560 602 $insertData,
561 603 $formDataRaw,
562 - $this->form
604 + $this->form,
563 605 ],
564 606 FLUENTFORM_FRAMEWORK_UPGRADE,
565 607 'fluentform/before_insert_submission',
566 608 'Use fluentform/before_insert_submission instead of fluentform_before_insert_submission.'
@@ -573,9 +615,9 @@
573 615 'fluentform_before_insert_payment_form',
574 616 [
575 617 $insertData,
576 618 $formDataRaw,
577 - $this->form
619 + $this->form,
578 620 ],
579 621 FLUENTFORM_FRAMEWORK_UPGRADE,
580 622 'fluentform/before_insert_payment_form',
581 623 'Use fluentform/before_insert_payment_form instead of fluentform_before_insert_payment_form.'
@@ -615,9 +657,8 @@
615 657 'source_id' => $insertId,
616 658 'component' => $type . ' Integration',
617 659 'status' => 'info',
618 660 'title' => __('Skip Submission Processing', 'fluentform'),
619 - 'description' => __('Submission marked as spammed. And skip all actions processing', 'fluentform')
661 + 'description' => __('Submission marked as spammed. And skip all actions processing', 'fluentform'),
620 662 ]);
621 663 }
622 664 }
623 -