Reputation: 10893
Is there any class in an html form that does not allow you to input or change the value in that text box. But you can see its content , for example the code below will allow you to see the content of the record in mysql database. But what I want is for it not to be edited. What would I add to the code below so that its content will not be editted by the users:
<tr>
<td><font size="3">Civil Status</td>
<td>:</td>
<td><input name="cs" type="text" maxlength="7" value="<?php echo $row["CSTAT"]; ?>"></td>
<td><font size="3">Age</td>
<td>:</td>
<td><input name="age" type="text" maxlength="3" value="<?php echo $row["AGE"]; ?>"></td>
<td><font size="3">Birthday</td>
<td>:</td>
<td><input name="bday" type="text" maxlength="12" value="<?php echo $row["BDAY"]; ?>"></td>
</tr>
<tr>
<td><font size="3">Address</td>
<td>:</td>
<td><input name="ad" type="text" maxlength="25" value="<?php echo $row["ADDRESS"]; ?>"></td>
<td><font size="3">Telephone #</td>
<td>:</td>
<td><input name="telnum" type="text" maxlength="11" value="<?php echo $row["TELNUM"]; ?>"></td>
<td width="23"><font size="3">Sex</td>
<td width="3">:</td>
<td width="174"><input name="sex" type="text" maxlength="1" value="<?php echo $row["SEX"]; ?>"></td>
</tr>
Upvotes: 12
Views: 91168
Reputation: 3721
You can try "disabled" OR "readonly"
<form>
<label for="disabled">Disabled</label><br>
<input name="disabled" value="disabled" disabled>
<br><br>
<label for="readonly">Read Only</label><br>
<input name="readonly" value="readonly" readonly>
</form>
Upvotes: 3
Reputation: 344491
What about the readonly attribute?
<input type="text" name="telnum" value="123456" readonly="readonly" />
Upvotes: 45
Reputation: 1017
Use the readonly attribute
<input readonly="value" />
http://www.w3schools.com/tags/att_input_readonly.asp
Upvotes: 2
Reputation: 799230
If you don't want it edited, and if there's no reason for it ever to be edited, then it shouldn't be in an input
element at all. Just echo it as normal text.
Upvotes: 4
Reputation: 125604
use readonly
http://www.w3schools.com/tags/att_input_readonly.asp
Upvotes: 2
Reputation: 15535
You can put readonly="readonly"
in your <input>
tag. You can also use disabled="disabled"
. Both provide varying degrees of "disabled-ness" as demonstrated here.
This is not fail-safe, though. Make sure that you do check when the form is POSTed back if the value has been modified - someone can craft a valid POST request with the field value modified - there's nothing you can do about that except check on the server-side if it's been modified from what it was originally.
Upvotes: 15