add form submission handling and confirmation emails

Validate form submissions and action configuration, execute finishers with submission context, and return JSON success or error responses. Add configurable confirmation emails to submitters and report failed submissions in the form UI.

Harden database and admin email finishers, and add submission handler and confirmation email checks.
This commit is contained in:
2026-11-24 11:26:37 +01:00
parent 80e60d6823
commit c507618b90
10 changed files with 593 additions and 47 deletions
@@ -70,6 +70,23 @@ $isEditing = isset($form['id']) && $form['id'] > 0;
if (type === 'radio') return 'Radio options (single selection)';
return 'Options';
},
setFinisherType(finisher, type) {
finisher.type = type;
if (type === 'sendConfirmationEmailToSubmitter' && (!finisher.options || typeof finisher.options !== 'object' || Array.isArray(finisher.options))) {
finisher.options = {
recipientField: '',
subject: 'Thank you for your submission',
message: 'Thank you for contacting us. We have received your message.'
};
}
},
init() {
this.finishers.forEach(finisher => {
if (finisher.type === 'sendConfirmationEmailToSubmitter') {
this.setFinisherType(finisher, finisher.type);
}
});
},
moveField(fromIndex, toIndex) {
if (toIndex < 0 || toIndex >= this.fields.length) return;
const field = this.fields.splice(fromIndex, 1)[0];
@@ -230,15 +247,38 @@ $isEditing = isset($form['id']) && $form['id'] > 0;
<div x-show="finishers.length > 0" class="space-y-2">
<template x-for="(finisher, index) in finishers">
<div class="flex items-center gap-3 p-3 border border-base-300 rounded-lg bg-base-200/50">
<span class="text-xs font-mono text-base-content/40">#[<span x-text="index + 1"></span>]</span>
<select x-model="finisher.type" class="select select-bordered select-sm flex-1">
<option value="saveToDatabase">Save to database</option>
<option value="sendMailToAdmin">Send email to admin</option>
</select>
<button @click="finishers.splice(index, 1)" type="button" class="btn btn-ghost btn-sm btn-circle text-error" title="Remove">
<i class="ph-duotone ph-trash"></i>
</button>
<div class="p-3 border border-base-300 rounded-lg bg-base-200/50 space-y-3">
<div class="flex items-center gap-3">
<span class="text-xs font-mono text-base-content/40">#[<span x-text="index + 1"></span>]</span>
<select :value="finisher.type" @change="setFinisherType(finisher, $event.target.value)" class="select select-bordered select-sm flex-1">
<option value="saveToDatabase">Save to database</option>
<option value="sendMailToAdmin">Send email to admin</option>
<option value="sendConfirmationEmailToSubmitter">Send confirmation email to submitter</option>
</select>
<button @click="finishers.splice(index, 1)" type="button" class="btn btn-ghost btn-sm btn-circle text-error" title="Remove">
<i class="ph-duotone ph-trash"></i>
</button>
</div>
<div x-show="finisher.type === 'sendConfirmationEmailToSubmitter'" class="space-y-3 pl-8">
<div class="form-control">
<label class="label"><span class="label-text">Recipient email field</span></label>
<select x-model="finisher.options.recipientField" class="select select-bordered select-sm w-full">
<option value="">Select an email field</option>
<template x-for="field in fields.filter(field => field.type === 'email')" :key="field.name">
<option :value="field.name" x-text="field.label + ' (' + field.name + ')' "></option>
</template>
</select>
<span x-show="fields.filter(field => field.type === 'email').length === 0" class="label-text-alt text-warning mt-1">Add an email field to the form before using this action.</span>
</div>
<div class="form-control">
<label class="label"><span class="label-text">Subject</span></label>
<input type="text" x-model="finisher.options.subject" class="input input-bordered input-sm w-full" />
</div>
<div class="form-control">
<label class="label"><span class="label-text">Message</span></label>
<textarea x-model="finisher.options.message" class="textarea textarea-bordered w-full" rows="4"></textarea>
</div>
</div>
</div>
</template>
</div>