Skip to content

Beautiful Open-Source Form Builder

Enhance Form Submission Logic to Preserve Existing Values

JhumanJe6d3c2e07105
diff --git a/api/app/Jobs/Form/StoreFormSubmissionJob.php b/api/app/Jobs/Form/StoreFormSubmissionJob.php
index 42a7f1adf..43f2ec11e 100644
--- a/api/app/Jobs/Form/StoreFormSubmissionJob.php
+++ b/api/app/Jobs/Form/StoreFormSubmissionJob.php
@@ -296,6 +296,11 @@ class StoreFormSubmissionJob implements ShouldQueue
&& !in_array($property['type'], ['files'])
&& !($property['type'] == 'url' && isset($property['file_upload']) && $property['file_upload']);
})->each(function (array $property) use (&$formData) {
+ // Do not override if a value is already set. We want to allow `0` and `false` as valid values.
+ if (isset($formData[$property['id']]) && $formData[$property['id']] !== '' && $formData[$property['id']] !== []) {
+ return;
+ }
+
if ($property['type'] === 'date' && isset($property['prefill_today']) && $property['prefill_today']) {
$formData[$property['id']] = now()->format((isset($property['with_time']) && $property['with_time']) ? 'Y-m-d H:i' : 'Y-m-d');
} else {
diff --git a/client/lib/forms/composables/useFormInitialization.js b/client/lib/forms/composables/useFormInitialization.js
index c3129c217..532e0632b 100644
--- a/client/lib/forms/composables/useFormInitialization.js
+++ b/client/lib/forms/composables/useFormInitialization.js
@@ -182,14 +182,16 @@ export function useFormInitialization(formConfig, form, pendingSubmission) {
*/
const updateSpecialFields = () => {
formConfig.value.properties.forEach(field => {
- // Handle date fields with prefill_today
- if (field.type === 'date' && field.prefill_today) {
+ // Handle date fields with prefill_today, only if no value is set
+ if (field.type === 'date' && field.prefill_today && form[field.id] == null) {
form[field.id] = new Date().toISOString()
}
- // Handle matrix fields with prefill data
- else if (field.type === 'matrix' && !form[field.id] && field.prefill) {
+ // Handle matrix fields with prefill data, only if no value is set
+ else if (field.type === 'matrix' && form[field.id] == null && field.prefill) {
form[field.id] = {...field.prefill}
- } else if (field.id && !form[field.id]) {
+ }
+ // Handle other fields with prefill data, only if no value is set
+ else if (field.id && form[field.id] == null && field.prefill) {
form[field.id] = field.prefill
}
})