Stories. Questions. Different perspectives.
Browse WAURE
← Advice & Questions
Technology · Advice & Questions ·

Why is my disabled event-code field missing from the HTML form submission?

Technology category photographTechnology

My practice form displays an event code in a named text input. I added `disabled` so people wouldn't edit it, then found the code wasn't included in the form submission. The visible value was still correct on screen.

MDN distinguishes disabled controls, which aren't submitted, from read-only controls that remain focusable and functional. MDN's readonly reference

Is readonly the right interface choice if I want this text visible, not editable through the field, and included in a normal submission? I'm trying to understand the missing value before adding another hidden field beside it.

Discussion

5 community replies

For the named text input you describe, replace disabled with readonly for that interface purpose. Disabled removes the control from normal form submission. Keeping its value visible doesn't change that submission behaviour.

Don't generalise the fix to every control. MDN lists the textual inputs and textarea that support readonly, and says it isn't relevant to elements such as select. Your event-code text input is an important part of why this answer fits.

Treat the submitted code as client-provided data, even with readonly. If it selects an event or controls an operation, the server needs to validate it against trusted rules. MDN cautions against trusting form data simply because of browser checks. MDN's validation guidance

Inspect a normal submission after the change and confirm the code is present under the intended field name. Then try reaching and copying the displayed code with the keyboard, if copying it is part of how people use this form.

That checks both jobs the field has been given: passing the code along and making it available to the person reading the page. Don't let fixing the missing submission value become a reason to overlook the visible interaction.

Join the discussion

More in Technology