cakephp忽略表单输入类型“数字”

时间:2015-05-29 08:52:04

标签: html5 cakephp-2.0 html-form html-input

我要做的是获取一个表单字段,只允许输入数字,但是当我尝试这个时:

<?php 
echo $this->Form->input('aht',array(
    'label' => 'AHT',
    'type' => 'number',
    'required' => true 
));
?>

cakephp输出:

<div class="input number">
  <label for="aht">AHT</label>
  <input id="aht" type="text" required="required" name="data[aht]">
</div>

而不是HTML 5输入类型“number”。 当尝试使用其他类型的文本时,它工作正常。 有什么想法吗?

CakePHP版本为2.5.4

1 个答案:

答案 0 :(得分:0)

将数据库中的aht字段更改为INT,这应该会“自动地”发生。

如果已经是这种情况,请尝试在模型中添加一些验证来定义数据类型,例如

public $validate = array(
    'aht' => array(
        'numeric' => array(
            'rule' => array('numeric'),
            'message' => 'AHT should be numeric',
        ),
    )
);