如果有可用数据,我正在输入项目,该字段应为只读 必填项目。
<input type="text" name="login_password"
id="login_password"
placeholder="Desgination" value="<?php echo
$row["designation"] ?>" Readonly required>
答案 0 :(得分:1)
您可以尝试一下,如果字段中有一些值,它将回显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"; ?> >
答案 1 :(得分:0)
我的2美分!如果没有在html代码中,那是个坏习惯,恕我直言
$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>
答案 2 :(得分:0)
尝试
<?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; ?>>