Orchard CMS — Disable submit button on dynamic form submit

George Roubie
1 min readOct 13, 2019

--

When a form is being submitted, sometimes, as the users are waiting, they might click more than once the submit button. This may cause duplicates submissions.

First, we will disable the submit button when the form is valid.

$('form').submit(function() {
if ($(this).valid()) {
$(this).find('button[type="submit"]').prop('disabled', true);
}
});

We can make it more beautiful if we add a loader as the user is waiting. For the loader in this example, I used FontAwesome Fonts 4.7.

$('form').submit(function () {
if ($(this).valid()) {
$(this).find('button[type="submit"]')
.prop('disabled', true)
.attr('style', 'background:none;border:none;')
.html('<i class="fa fa-spinner fa-spin"></i>');
}
});

This feature is already installed in this head start Orchard CMS theme.

Originally published at https://orchardtricks.dotnest.com.

--

--

George Roubie
George Roubie

Written by George Roubie

Experienced Software Engineer with more than 10 years of experience, specialized in Front-End Web technologies, with strong foundations in programming.

No responses yet