Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabled form fields not submitting data [duplicate]

Is there any way (with a attribute flag or something like that) to enable form fields that are disabled to submit data?

Or, if that's not possible, is there any way to block fields from editing with css or any other attribute than disabled without hiding them?

My special case at the moment is an identifier for a data-set that should be shown in the form (uneditable) - if there is no better solution I think i'll use a hidden field in addition to the disabled one to hold the actual value with the disabled one showing it.

like image 501
bardiir Avatar asked Jan 19 '12 12:01

bardiir


People also ask

Do disabled form fields get submitted?

If a field is disabled , the value of the field is not sent to the server when the form is submitted. If a field is readonly , the value is sent to the server.

How do I post 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.

What is the difference between disabled and readonly property?

The difference between disabled and readonly is that read-only controls can still function and are still focusable, whereas disabled controls can not receive focus and are not submitted with the form and generally do not function as controls until they are enabled.

How do you make a form Disabled in HTML?

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. Tip: Disabled <input> elements in a form will not be submitted!


1 Answers

As it was already mentioned: READONLY does not work for <input type='checkbox'> and <select>...</select>.

If you have a Form with disabled checkboxes / selects AND need them to be submitted, you can use jQuery:

$('form').submit(function(e) {     $(':disabled').each(function(e) {         $(this).removeAttr('disabled');     }) }); 

This code removes the disabled attribute from all elements on submit.

like image 81
Mario Werner Avatar answered Nov 15 '22 16:11

Mario Werner