如何在php中只读文本框

时间:2022-08-25 17:22:51

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.

我只希望某些用户只读取值而无法更改它。

5 个解决方案

#1


15  

Try like

试试吧

<?php 
  echo form_input(array('name'=>'price','value'=>$item['price'],'size'=>'6',
     'readonly'=>'true'));
      //Or 'readonly'=>'readonly'
?>

#2


3  

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

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

echo form_input($options);

#3


2  

You can do it with:

你可以这样做:

<?php 
  echo form_input(array('name'=>'price','value'=>$item['price'],'size'=>'6',
     'readonly'=>'readonly')); 
?>

This will be xhtml compatible.

这将是xhtml兼容的。

Just be sure to NOT read it on server side, don't trust on client data, because HTML can be changed to allow to modify values.

请确保不要在服务器端读取它,不要信任客户端数据,因为可以更改HTML以允许修改值。

#4


1  

# Try pure PHP
if(isset($_POST['something'])){
# Do not set the readonly attribute
$readonly ='';
}else{
# Set the readonly attribute
$readonly = 'readonly';
}
<input type="text" <?php echo $readonly; ?>>

#5


0  

There are many ways to do this:

有很多方法可以做到这一点:

from CI form field:

来自CI表格字段:

  echo form_input(array('name'=>'price','value'=>$item['price'],'size'=>'6','readonly'=>'true'));

from jquery/javascript:

来自jquery / javascript:

using id of the field as:

使用该字段的id为:

 $("#id_offield").attr("readonly",true);

in html:

在HTML中:

<textarea rows="4" cols="50" readonly>

etc!

等等!

hope it will help!

希望它会有所帮助!

#1


15  

Try like

试试吧

<?php 
  echo form_input(array('name'=>'price','value'=>$item['price'],'size'=>'6',
     'readonly'=>'true'));
      //Or 'readonly'=>'readonly'
?>

#2


3  

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

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

echo form_input($options);

#3


2  

You can do it with:

你可以这样做:

<?php 
  echo form_input(array('name'=>'price','value'=>$item['price'],'size'=>'6',
     'readonly'=>'readonly')); 
?>

This will be xhtml compatible.

这将是xhtml兼容的。

Just be sure to NOT read it on server side, don't trust on client data, because HTML can be changed to allow to modify values.

请确保不要在服务器端读取它,不要信任客户端数据,因为可以更改HTML以允许修改值。

#4


1  

# Try pure PHP
if(isset($_POST['something'])){
# Do not set the readonly attribute
$readonly ='';
}else{
# Set the readonly attribute
$readonly = 'readonly';
}
<input type="text" <?php echo $readonly; ?>>

#5


0  

There are many ways to do this:

有很多方法可以做到这一点:

from CI form field:

来自CI表格字段:

  echo form_input(array('name'=>'price','value'=>$item['price'],'size'=>'6','readonly'=>'true'));

from jquery/javascript:

来自jquery / javascript:

using id of the field as:

使用该字段的id为:

 $("#id_offield").attr("readonly",true);

in html:

在HTML中:

<textarea rows="4" cols="50" readonly>

etc!

等等!

hope it will help!

希望它会有所帮助!