POST values of disabled form elements

bikey77 picture bikey77 · Oct 18, 2011 · Viewed 11.8k times · Source

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; 

}

Answer

Madara's Ghost picture Madara's Ghost · Oct 18, 2011

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 :)