Skip to content Skip to sidebar Skip to footer

"protect" Text Box Value From Input (html Form)

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

Solution 1:

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.

Solution 2:

Set the readonly property of the input element:

<input type="text"readonly="readonly" />

This will prevent any modification (except if the user edits with a DOM Inspector). Always validate input on the server. If you do not want any changes made, don't allow the user to edit it.

http://www.w3schools.com/tags/att_input_readonly.asp

Solution 3:

Just do this

<input type="text" value="VALUE"readonly />

Then itll be read only :)

Solution 4:

<input type="text" readonly="readonly"/>. But: Never be sure, and validate data on the server side. It is very easy to request GET/POST with invalid data.

Solution 5:

Form inputs have a 'disabled' and 'readonly' attributes you can set to make them un-editable.

http://htmlhelp.com/reference/html40/forms/input.html

Though you can never be 100% sure what is getting sent from the client side. The entire DOM is editable by the client.

Post a Comment for ""protect" Text Box Value From Input (html Form)"