Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make a textbox readonly in php

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.

like image 691
user1796164 Avatar asked Mar 20 '13 13:03

user1796164


People also ask

How do I make my TextBox readonly?

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.

How can I make text field non editable in PHP?

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.

How do I make a TextBox non editable?

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 can you set a read only field?

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.


2 Answers

Try like

<?php 
  echo form_input(array('name'=>'price','value'=>$item['price'],'size'=>'6',
     'readonly'=>'true'));
      //Or 'readonly'=>'readonly'
?>
like image 110
Gautam3164 Avatar answered Oct 09 '22 13:10

Gautam3164


$options    =   array(
                    'name'      =>  'price',
                    'value'     =>  $item['price'],
                    'size'      =>  '6'
);

if(!$allowed_user){
    $options['readonly']    =   'readonly'
}

echo form_input($options);
like image 40
Muhammad Raheel Avatar answered Oct 09 '22 13:10

Muhammad Raheel