"Protect" text box value from input (HTML form)

Trufa picture Trufa · Nov 17, 2010 · Viewed 32.5k times · Source

I was wondering whether it is possible to assign a value to an HTML text box and protect it.

What I mean is make it´s content unmodifiable, so that when the form gets submitted im "sure" it was this value which was submitted.

BTW I realize the easier way would be not to "listen" fot this input and just assign it but it would come in handy to be able to do what´s stated above.

I hope the question is clear enough, please ask for any needed clarification.

Thanks in advance!

EDIT: I was definitely not clear enough but I tried to express that i should hold the value after submitted (not modifiable in client side)

Answer

Matthew Flaschen picture Matthew Flaschen · Nov 17, 2010

No, it's not. You should never trust user input, which includes form submissions.

The other answers tell you how to mark the field as read-only. This is useful if you want to display a particular value, while showing that it's not intended to edited.

However, it can still be modified with Firebug, DOM Inspector, etc. Or, they can just submit a HTTP request without using the browser at all.

I would recommend storing the value in a session instead.