| @@ -78,31 +78,15 @@ | ||
| 78 | 78 | return null !== $value && false !== $value && '' !== $value; |
| 79 | 79 | }); |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - // Process "Other" options for checkboxes and radio fields | |
| 83 | - 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) { | |
| 84 | 84 | $fieldName = str_replace('__ff_other_input__', '', $name); |
| 85 | - // Store with the field's own (translated) "Other" label as prefix | |
| 86 | - $rawField = Arr::get(FormFieldsParser::getInputs($this->form, ['raw']), $fieldName . '.raw', []); | |
| 87 | - $otherPrefix = Helper::getOtherOptionValuePrefix($rawField, $this->form); | |
| 88 | 85 | |
| 89 | - // Handle checkbox fields (array values) | |
| 90 | - if (isset($formDataRaw[$fieldName]) && is_array($formDataRaw[$fieldName])) { | |
| 91 | - $selectedValues = $formDataRaw[$fieldName]; | |
| 92 | - | |
| 93 | - // Handle field-specific "Other" values | |
| 94 | - $otherValue = '__ff_other_' . $fieldName . '__'; | |
| 95 | - | |
| 96 | - $key = array_search($otherValue, $selectedValues); | |
| 97 | - | |
| 98 | - if (false !== $key) { | |
| 99 | - $selectedValues[$key] = $otherPrefix . sanitize_text_field($input); | |
| 100 | - $formDataRaw[$fieldName] = $selectedValues; | |
| 101 | - } | |
| 102 | - } elseif (isset($formDataRaw[$fieldName]) && '__ff_other_' . $fieldName . '__' === $formDataRaw[$fieldName]) { | |
| 103 | - // Handle radio fields (single value) | |
| 104 | - $formDataRaw[$fieldName] = $otherPrefix . 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); | |
| 105 | 89 | } |
| 106 | 90 | |
| 107 | 91 | unset($formDataRaw[$name]); |
| 108 | 92 | } |
| @@ -126,9 +110,54 @@ | ||
| 126 | 110 | |
| 127 | 111 | $this->formData = array_intersect_key($formData, $acceptedFieldKeys); |
| 128 | 112 | } |
| 129 | 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); | |
| 130 | 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 | + | |
| 131 | 160 | /** |
| 132 | 161 | * Prepare the data to be inserted to the database. |
| 133 | 162 | * |
| 134 | 163 | * @param boolean $formData |
| @@ -299,9 +328,13 @@ | ||
| 299 | 328 | if (empty($form->settings)) { |
| 300 | 329 | $formSettings = FormMeta::retrieve('formSettings', $form->id); |
| 301 | 330 | $form->settings = is_array($formSettings) ? $formSettings : []; |
| 302 | 331 | } |
| 303 | - $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 | + } | |
| 304 | 337 | $confirmation = apply_filters_deprecated( |
| 305 | 338 | 'fluentform_form_submission_confirmation', |
| 306 | 339 | [ |
| 307 | 340 | $confirmation, |
| @@ -320,9 +353,9 @@ | ||
| 320 | 353 | $form |
| 321 | 354 | ); |
| 322 | 355 | if ('samePage' == Arr::get($confirmation, 'redirectTo')) { |
| 323 | 356 | |
| 324 | - $confirmation['messageToShow'] = fluentform_sanitize_html($confirmation['messageToShow']); | |
| 357 | + $confirmation['messageToShow'] = fluentform_sanitize_html(Arr::get($confirmation, 'messageToShow', '')); | |
| 325 | 358 | |
| 326 | 359 | $confirmation['messageToShow'] = apply_filters_deprecated( |
| 327 | 360 | 'fluentform_submission_message_parse', |
| 328 | 361 | [ |
| @@ -352,14 +385,14 @@ | ||
| 352 | 385 | $message = $message ? $message : __('The form has been successfully submitted.', 'fluentform'); |
| 353 | 386 | |
| 354 | 387 | $returnData = [ |
| 355 | 388 | 'message' => $message, |
| 356 | - 'action' => $confirmation['samePageFormBehavior'], | |
| 389 | + 'action' => Arr::get($confirmation, 'samePageFormBehavior', 'hide_form'), | |
| 357 | 390 | ]; |
| 358 | 391 | } else { |
| 359 | 392 | $redirectUrl = Arr::get($confirmation, 'customUrl'); |
| 360 | - if ('customPage' == $confirmation['redirectTo']) { | |
| 361 | - $redirectUrl = get_permalink($confirmation['customPage']); | |
| 393 | + if ('customPage' === Arr::get($confirmation, 'redirectTo')) { | |
| 394 | + $redirectUrl = get_permalink(Arr::get($confirmation, 'customPage')); | |
| 362 | 395 | } |
| 363 | 396 | $enableQueryString = Arr::get($confirmation, 'enable_query_string') === 'yes'; |
| 364 | 397 | $queryStrings = Arr::get($confirmation, 'query_strings'); |
| 365 | 398 | |