Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"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 "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)

like image 995
Trufa Avatar asked Nov 17 '10 20:11

Trufa


People also ask

How do I restrict text input in HTML?

The HTML <input> tag is used to get user input in HTML. To give a limit to the input field, use the min and max attributes, which is to specify a maximum and minimum value for an input field respectively. To limit the number of characters, use the maxlength attribute.

How do I make a textbox non-editable in HTML?

The readonly attribute makes a form control non-editable (or “read only”). A read-only field can't be modified, but, unlike disabled , you can tab into it, highlight it, and copy its contents. Setting the value to null does not remove the effects of the attribute. Instead use removeAttribute('readonly') .

How do you restrict values in HTML?

The standard solution to restrict a user to enter only numeric values is to use <input> elements of type number. It has built-in validation to reject non-numerical values. This is demonstrated below: HTML.

How do you make an input field Uneditable?

The readonly attribute is a boolean attribute. When present, it specifies that an input field is read-only. A read-only input field cannot be modified (however, a user can tab to it, highlight it, and copy the text from it).


2 Answers

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.

like image 127
Matthew Flaschen Avatar answered Oct 01 '22 15:10

Matthew Flaschen


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

like image 20
Evan Mulawski Avatar answered Oct 01 '22 14:10

Evan Mulawski