POST values โ€‹โ€‹for locked form elements

I have a form in which I need to turn off an array of checkboxes and several fields so that the user cannot change / change their values. When I submit the form, the POST values โ€‹โ€‹for disabled items are missing / null. How can I control what I'm trying to do without this problem?

Now I will disable the fields by disconnecting the div container as follows:

#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; } 
+7
source share
4 answers

Well, there are 3 solutions that I can think of:

  • Make them readonly by adding the readonly property to the element.
  • disable them in CSS / JavaScript. Color it as it is disabled, and do not allow editing using JavaScript,
  • Leave it disconnected and delete disconnected when sending.

Make a choice:)

+23
source

you can use readonly instead of disabled , for the user itโ€™s almost the same (there cannot be an editet), but readonly -elements are passed, but disabled is not.

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

Disabled attribute

  • Values โ€‹โ€‹for locked form elements are not passed to the processor method. W3C calls this a successful item. (This works similarly to forms that are not marked.)
  • Some browsers may override or provide a default style for disabled form elements. (Gray or bumpy text) Internet Explorer 5.5 is especially nasty about this.
  • Disabled form elements do not receive focus.
  • Disabled form elements are skipped in the tab navigation.

Read-only attribute

  • Not all form elements have a readonly attribute. The most visible as well as the elements do not have readonly attributes (although you both have disabled attributes)
  • Browsers do not provide default overridden visual feedback that a form element reads only. (This may be a problem ... see below.)
  • Form elements with a set of readonly attributes are passed to the form processor.
  • Read-only form elements can get focus
  • Read-only items are included in the tabbed navigation.
+6
source

Sending the same data doesn't make much sense.

Just leave it on the server side and then use it when sending.

Moreover, considering that

user cannot change / change his values.

pretty stupid.

+2
source

You can use read-only instead of disabled, which should have the desired effect

You can also use javascript to submit your form and pre-submit un-disable (enable: P) various fields?

0
source

All Articles