How can I make a textbox readonly in this code
<?php
echo form_input(array(
'name'=>'price',
'value'=>$item['price'],
'size'=>'6'
));
?>
I want only certain users to only read the value and not be able to change it.
Set the TextBox control's ReadOnly property to true . With the property set to true , users can still scroll and highlight text in a text box without allowing changes.
You can use readonly attribute, if you want your input only to be read. And you can use disabled attribute, if you want input to be shown, but totally disabled (even processing languages like PHP wont be able to read those). When you send form to a php file, it won't read disabled inputs.
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') .
The readonly attribute of <input> element is used to specify that the input field is read-only. If an input is readonly, then it's content cannot be changed but can be copied and highlighted. It is a boolean attribute. Example: This example using <input> readonly attribute to set the read-only value.
Try like
<?php
echo form_input(array('name'=>'price','value'=>$item['price'],'size'=>'6',
'readonly'=>'true'));
//Or 'readonly'=>'readonly'
?>
$options = array(
'name' => 'price',
'value' => $item['price'],
'size' => '6'
);
if(!$allowed_user){
$options['readonly'] = 'readonly'
}
echo form_input($options);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With