codeigniter 如何将输入字段设置为只读或输入字段

ee7vknir  于 2022-12-07  发布在  其他
关注(0)|答案(3)|浏览(196)

我有输入项,如果数据可用,则字段应为只读,否则为必填字段。

<input type="text" name="login_password" 
  id="login_password" 
 placeholder="Desgination" value="<?php echo 
   $row["designation"] ?>" Readonly required>
yqkkidmi

yqkkidmi1#

您可以尝试此操作,如果字段中存在某些值,它将回显readonly,否则它将是空白字段,并显示required

<input type="text" name="login_password"   id="login_password"  placeholder="Desgination" value="<?php echo  $row["designation"]; ?>"  <?php if(trim($row["designation"]) !="") echo "Readonly"; else echo "required"; ?> >
kiayqfof

kiayqfof2#

我的2分钱!没有如果在html代码,一个坏习惯imho

$readonly = isset($row["designation"]) ? 'required' : '';

<input type="text" name="login_password" id="login_password" placeholder="Desgination" value="<?php echo $row["designation"] ?>" <?php echo $readonly; ?> required>
pdtvr36n

pdtvr36n3#

试试这个

<?php 
    if(!empty($row["designation"])){
       $condition = "readonly";
    else
      $condition = "required"; 
?>
<input type="text" name="login_password" id="login_password" placeholder="Desgination" value="<?php echo 
$row["designation"] ?>" <?php echo $condition; ?>>

相关问题