Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

submit disabled fields

I know the defined behavior for web forms is to not submit disabled fields... but that's not the definition I want. I want to use ajax to post the form and I want it to get all fields, even if they are disabled. I don't want to build a workaround where I make the field "look disabled"... or have to hack it where I enable the fields -> post -> disable.

is it possible to make ajaxSubmit() or serialize() grab the disabled fields as it's moving through the DOM and grabbing values? or is there another serialize plugin out there that can do this? or does someone have a mod I can make to one of these plugins to make it work?

or am I doomed to hack it?

like image 489
Nick Franceschina Avatar asked Aug 16 '09 14:08

Nick Franceschina


People also ask

How do I submit a disabled field?

To submit the value of a disabled input field with HTML, we replace the disabled attribute with the readonly attribute. to set the readonly attribute to readonly . This way, the user won't be able to interact with the input, but the input value will still be submitted.

Do disabled fields get submitted?

They don't get submitted, because that's what it says in the W3C specification. Controls that are disabled cannot be successful.

What will happen when the disabled value is submitted?

A disabled input element is unusable and un-clickable. The disabled attribute can be set to keep a user from using the <input> element until some other condition has been met (like selecting a checkbox, etc.). Then, a JavaScript could remove the disabled value, and make the <input> element usable.

What is disabled attribute in HTML?

The disabled attribute is a boolean attribute. When present, it specifies that the element should be disabled. A disabled element is unusable. The disabled attribute can be set to keep a user from using the element until some other condition has been met (like selecting a checkbox, etc.).


1 Answers

You can make your fields readonly, this will disallow changes to the value of your controls.

Edit: You could easily write a "serializeDisabled" function, iterating over the disabled form elements which have a name attribute and using the jQuery.param function at the end, to generate the serialized string:

(function ($) {   $.fn.serializeDisabled = function () {     var obj = {};      $(':disabled[name]', this).each(function () {          obj[this.name] = $(this).val();      });     return $.param(obj);   } })(jQuery); 
like image 63
Christian C. Salvadó Avatar answered Oct 05 '22 13:10

Christian C. Salvadó