Submitting Disabled Fields

The "disabled" attribute for form fields is a great little user interface helper that you can use to help protect data from accidental changes. It locks down an HTML input form element so that it can be viewed, but not be changed. This is handy when displaying a form to a user where you need an extra layer of protection for the data.

What happens when the user goes to submit a form with disabled elements? The value of the disabled elements are not passed back to the browser - this can quickly turn into a data validation and/or submission issue.

Luckily, there's a quick way to fix this with a bit of jQuery. With just 3 lines of code, you can enabled (un-disable?) all fields on the form when the user clicks the "submit" button:

$('input#edit-submit').click(function() {
  $('input').removeAttr('disabled');
});

You'll probably want to modify this code a little bit to better target the disabled elements, but this should get you going in the right direction.

Comments

Does this still work?

Submitted by Guest (not verified) on Tue, 09/17/2013 - 11:39

Author comment

Yes - this should still work fine.

-mike

Submitted by ultimike on Tue, 09/17/2013 - 11:42

In reply to by Guest (not verified)