使用php检查输入字段的类型

时间:2012-10-10 06:16:41

标签: php types input

我想检查一下输入字段文本的类型。因为我只想让thos字段只读。我知道我可以用javascript做到这一点,但有没有办法在PHP中实现这一点?

最好的regrads。

3 个答案:

答案 0 :(得分:1)

与javascript一样使用此

 <input name="address" type="text" readonly="readonly">

这个make字段只读,你不能改变它。

 <input name="address" type="text" value="<?php echo "your value"; ?>" readonly="readonly">

试试这段代码

答案 1 :(得分:0)

要禁用输入字段添加已禁用的属性:

 disabled="disabled"

这必须在生成html或生成后使用javascript时完成。

这是一种干净的方式,用户直接看到它只是可读但不可编辑。

当你提交表单时,在php中你可以使用name属性来获取发布的值。说你有

<input name="address" type="text">

在php中:

if($_POST['address']){
   //don't process address cause you know this is of type text
}

答案 2 :(得分:0)

如果$ field为false,则设置输入禁用

,这是你在php中的方法
<input type="text" name="" <?php echo ($field == false)? 'disabled="disabled"' : '';?> value="" />
相关问题