SweetAlert2
Set responseType: 'swal' to show a modal on success and a toast on error, instead of inline-only feedback. Field errors still appear next to inputs.
formsub does not bundle SweetAlert2. Load it yourself so Swal exists on window.
1. Load SweetAlert2
html
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>2. Enable it
html
<form id="contact-form">
<!-- fields -->
<button type="submit" id="submit-button">Send</button>
</form>
<script src="/path/to/formsub.min.js"></script>
<script>
formsub.newForm({
formId: 'contact-form',
submitButton: '#submit-button',
ajaxUrl: '/api/contact',
responseType: 'swal',
});
</script>What the user sees
| Outcome | UI |
|---|---|
| Success | Modal with response.message as plain text |
| Error | Toast with response.message |
Field errors | Inline errors next to fields and an error toast |
The confirm button label uses the i18n key ok (default: “OK”). See Internationalization.
If Swal is not loaded, swal UI is skipped silently. Inline field errors still work.
Do not use Swal html
Messages are shown with text / toast title so a server payload cannot inject markup. Do not switch this to html for untrusted responses.