{% import '_includes/forms' as forms %} {% import 'formie/_macros' as formieMacros %} {% import 'verbb-base/_macros' as macros %}

{{ 'Form Submission' | t('formie') }}

{% set submitMethod = form.settings.submitMethod ?? 'page-reload' %} {% set submitAction = form.settings.submitAction ?? 'message' %} {# Force Ajax if the form contains some payment fields, due to 3DS requirements #}
{{ forms.selectField({ label: 'Submission Method' | t('formie'), instructions: 'Whether to reload the page when this form is submitted, or use Ajax to send this form without reloading the page.' | t('formie'), id: 'submitMethod', name: 'settings[submitMethod]', options: [{ label: 'Ajax (Client-side)' | t('formie'), value: 'ajax', }], value: submitMethod, warning: 'You must use Ajax submissions when using some payment integrations in your form.' | t('formie'), }) }} {# Spacing fix #}
{{ forms.selectField({ label: 'Submission Method' | t('formie'), instructions: 'Whether to reload the page when this form is submitted, or use Ajax to send this form without reloading the page.' | t('formie'), id: 'submitMethod', name: 'settings[submitMethod]', options: [{ label: 'Page Reload (Server-side)' | t('formie'), value: 'page-reload', }, { label: 'Ajax (Client-side)' | t('formie'), value: 'ajax', }], value: submitMethod, }) }} {# Spacing fix #}
{{ forms.selectField({ label: 'Action on Submit' | t('formie'), instructions: 'When a user submits this form, I want to:' | t('formie'), id: 'submitAction', name: 'settings[submitAction]', value: submitAction, inputAttributes: { 'data-value': submitAction, 'data-target-prefix': 'submit-action-', }, }) }}
{{ forms.lightswitchField({ label: 'Hide Form' | t('formie'), instructions: 'Whether to hide the form and only show the success message.' | t('formie'), id: 'submitActionFormHide', name: 'settings[submitActionFormHide]', on: form.settings.submitActionFormHide ?? false, }) }} {{ forms.textField({ label: 'Submission Message Timeout' | t('formie'), instructions: 'The number of seconds to automatically hide the message. Leave empty to disable hiding.' | t('formie'), id: 'submitActionMessageTimeout', name: 'settings[submitActionMessageTimeout]', type: 'number', size: 3, value: form.settings.submitActionMessageTimeout ?? null, }) }} {{ forms.selectField({ label: 'Submission Message Position' | t('formie'), instructions: 'Where to position the success message in the form, when shown.' | t('formie'), name: 'settings[submitActionMessagePosition]', options: [ { label: 'None' | t('formie'), value: '' }, { label: 'Top of Form' | t('formie'), value: 'top-form' }, { label: 'Bottom of Form' | t('formie'), value: 'bottom-form' }, ], value: form.settings.submitActionMessagePosition ?? 'top-form', }) }}
{{ formieMacros.siteElementSelectField({ label: 'Redirect Entry' | t('formie'), instructions: 'Select an entry for the user to be redirected to.' | t('formie'), id: 'submitActionEntryId', name: 'submitActionEntryId', limit: 1, elementType: 'craft\\elements\\Entry', elements: form.redirectEntry ? [ form.redirectEntry ] : [], showSiteMenu: true, jsClass: 'Craft.Formie.SiteElementSelect', }) }} {{ forms.selectField({ label: 'Redirect Option' | t('formie'), instructions: 'How to redirect the user after submission, whether in the same tab, or a new tab.' | t('formie'), id: 'submitActionTab', name: 'settings[submitActionTab]', disabled: (submitAction == 'entry') ? false : true, disabled: (submitAction == 'entry' or submitAction == 'url') ? false : true, options: [{ label: 'Redirect on the same tab' | t('formie'), value: 'same-tab', }, { label: 'Redirect on a new tab' | t('formie'), value: 'new-tab', }], value: form.settings.submitActionTab ?? 'same-tab', }) }}
{{ forms.textField({ label: 'Redirect URL' | t('formie'), instructions: 'The full URL that the user to be redirected to.' | t('formie'), id: 'submitActionUrl', name: 'settings[submitActionUrl]', value: form.settings.submitActionUrl ?? null, }) }} {{ forms.selectField({ label: 'Redirect Option' | t('formie'), instructions: 'How to redirect the user after submission, whether in the same tab, or a new tab.' | t('formie'), id: 'submitActionTab', name: 'settings[submitActionTab]', disabled: (submitAction == 'url') ? false : true, disabled: (submitAction == 'entry' or submitAction == 'url') ? false : true, options: [{ label: 'Redirect on the same tab' | t('formie'), value: 'same-tab', }, { label: 'Redirect on a new tab' | t('formie'), value: 'new-tab', }], value: form.settings.submitActionTab ?? 'same-tab', }) }}

{{ 'This will reload the page, clearing the form of values, and showing no success message.' | t('formie') }}

{{ 'This will clear the form of values, and showing no success message.' | t('formie') }}

{{ forms.selectField({ label: 'Loading Indicator' | t('formie'), instructions: 'Whether to show a loading indicator when submitting the form. This will be shown on the submit button.' | t('formie'), id: 'loadingIndicator', name: 'settings[loadingIndicator]', options: [{ label: 'None' | t('formie'), value: '', }, { label: 'Spinner' | t('formie'), value: 'spinner', }, { label: 'Text' | t('formie'), value: 'text', }], toggle: true, targetPrefix: 'loading-indicator-', value: form.settings.loadingIndicator ?? '', }) }}

{{ 'Validation' | t('formie') }}

{{ forms.lightswitchField({ label: 'Validate Form on Submit' | t('formie'), instructions: 'Whether to validate the form client-side, when the user submits the form. This will show errors as soon as the submit button is pressed. Forms will also always be validated server-side.' | t('formie'), id: 'validationOnSubmit', name: 'settings[validationOnSubmit]', on: form.settings.validationOnSubmit ?? true, }) }} {{ forms.lightswitchField({ label: 'Validate When Typing' | t('formie'), instructions: 'Whether to validate each field as the user types, so that errors will appear immediately.' | t('formie'), id: 'validationOnFocus', name: 'settings[validationOnFocus]', on: form.settings.validationOnFocus ?? false, }) }} {{ forms.selectField({ label: 'Error Message Position' | t('formie'), instructions: 'Where to position the error message in the form, when shown.' | t('formie'), name: 'settings[errorMessagePosition]', options: [ { label: 'None' | t('formie'), value: '' }, { label: 'Top of Form' | t('formie'), value: 'top-form' }, { label: 'Bottom of Form' | t('formie'), value: 'bottom-form' }, ], value: form.settings.errorMessagePosition ?? 'top-form', }) }}

{{ 'Restrictions' | t('formie') }}

{{ forms.lightswitchField({ label: 'Require Logged-in User' | t('formie'), instructions: 'Whether this form can be viewed only by logged-in users.' | t('formie'), id: 'requireUser', name: 'settings[requireUser]', toggle: '#require-user', on: form.settings.requireUser ?? false, }) }} {{ forms.lightswitchField({ label: 'Schedule Form' | t('formie'), instructions: 'Whether this form should only be available on a schedule.' | t('formie'), id: 'scheduleForm', name: 'settings[scheduleForm]', toggle: '#schedule-form', on: form.settings.scheduleForm ?? false, }) }} {{ forms.lightswitchField({ label: 'Limit Submissions' | t('formie'), instructions: 'Whether submissions for this form should be limited to a number.' | t('formie'), id: 'limitSubmissions', name: 'settings[limitSubmissions]', toggle: '#limit-submissions', on: form.settings.limitSubmissions ?? false, }) }} {% set actionOptions = { 'page-reload': [ { label: 'Display a message' | t('formie'), value: 'message', }, { label: 'Redirect to an entry' | t('formie'), value: 'entry', }, { label: 'Redirect to a URL' | t('formie'), value: 'url', }, { label: 'Reload the page' | t('formie'), value: 'reload', }, ], 'ajax': [ { label: 'Display a message' | t('formie'), value: 'message', }, { label: 'Redirect to an entry' | t('formie'), value: 'entry', }, { label: 'Redirect to a URL' | t('formie'), value: 'url', }, { label: 'Reset form values' | t('formie'), value: 'reset', }, ], } %} {% js %} // "Action on Submit" has dynamic options, depending on the "Submission Method" function updateSubmitActionOptions() { var $submitAction = $('[name="settings[submitAction]"]'); var $submitMethod = $('[name="settings[submitMethod]"]'); var allOptions = {{ actionOptions | json_encode | raw }}; var options = allOptions[$submitMethod.val()]; var selectedOption = $submitAction.val() || $submitAction.data('value'); var output = []; $.each(options, function(index, option) { output.push(''); }); $submitAction.html(output.join('')); // Restore the original value $submitAction.val(selectedOption); // Manually find the toggle - Craft doesn't like it when set initially and values change dynamically $submitAction.fieldtoggle(); } $('[name="settings[submitMethod]"]').on('change', function(e) { updateSubmitActionOptions(); // Hide the panes that are unique to specific submit methods, as they'll stick around otherwise $('#submit-action-reload').addClass('hidden'); $('#submit-action-reset').addClass('hidden'); }); updateSubmitActionOptions(); {% endjs %}