Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

POST values of disabled form elements

I have a form in which I need to disable an array of checkboxes and a few fields so that the user cannot change/alter their values. When I submit the form though, the POST values of the disabled elements are missing/null. How can I manage what I'm trying to do without this problem?

Right now I'm disabling the fields by disabling the container div like this:

#unselectable {
    -moz-user-select: -moz-none;
    -khtml-user-select: none;
    -webkit-user-select: none;
    -o-user-select: none;
    -webkit-user-select: none;
    cursor:not-allowed; 

}
like image 921
bikey77 Avatar asked Oct 18 '11 10:10

bikey77


2 Answers

Well, there are 3 solutions I can think of:

  • Make them readonly by adding the readonly property to the element.
  • disable them in CSS/JavaScript. Color it like it's disabled, and don't allow editing with JavaScript,
  • Leave it disabled, and remove the disabled on submit.

Take your pick :)

like image 118
Madara's Ghost Avatar answered Oct 22 '22 16:10

Madara's Ghost


you could use readonly instead of disabled wich is almost the same for the user (can't be editet) but the values of readonly-elements get submitted while the disabled ones don't.

note that there are some other differences between readonly and disabled wich might lead to other problems for you:

The Disabled attribute

  • Values for disabled form elements are not passed to the processor method. The W3C calls this a successful element.(This works similar to form check boxes that are not checked.)
  • Some browsers may override or provide default styling for disabled form elements. (Gray out or emboss text) Internet Explorer 5.5 is particularly nasty about this.
  • Disabled form elements do not receive focus.
  • Disabled form elements are skipped in tabbing navigation.

The Read Only Attribute

  • Not all form elements have a readonly attribute. Most notable, the , , and elements do not have readonly attributes (although thy both have disabled attributes)
  • Browsers provide no default overridden visual feedback that the form element is read only. (This can be a problem… see below.)
  • Form elements with the readonly attribute set will get passed to the form processor.
  • Read only form elements can receive the focus
  • Read only form elements are included in tabbed navigation.
like image 24
oezi Avatar answered Oct 22 '22 16:10

oezi