tags:

views:

78

answers:

5

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>
+2  A: 

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.

Andy Shellam
The addendum about checking the value on the backend is very important.
D_N
+1  A: 

use readonly

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

Haim Evgi
+1  A: 

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.

Ignacio Vazquez-Abrams
+1  A: 

Use the readonly attribute

<input readonly="value" />

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

hearn
+2  A: 

What about the readonly attribute?

<input type="text" name="telnum" value="123456" readonly="readonly" />
Daniel Vassallo
ok thanks, this is what I needed:)