Disabled form inputs do not appear in the request

后端 未结 11 1857
暗喜
暗喜 2020-11-22 04:37

I have some disabled inputs in a form and I want to send them to a server, but Chrome excludes them from the request.

Is there any workaround for this without addin

11条回答
  •  北海茫月
    2020-11-22 05:06

    Semantically this feels like the correct behaviour

    I'd be asking myself "Why do I need to submit this value?"

    If you have a disabled input on a form, then presumably you do not want the user changing the value directly

    Any value that is displayed in a disabled input should either be

    1. output from a value on the server that produced the form, or
    2. if the form is dynamic, be calculable from the other inputs on the form

    Assuming that the server processing the form is the same as the server serving it, all the information to reproduce the values of the disabled inputs should be available at processing

    In fact, to preserve data integrity - even if the value of the disabled input was sent to the processing server, you should really be validating it. This validation would require the same level of information as you would need to reproduce the values anyway!

    I'd almost argue that read-only inputs shouldn't be sent in the request either

    Happy to be corrected, but all the use cases I can think of where read-only/disabled inputs need to be submitted are really just styling issues in disguise

提交回复
热议问题