【问题标题】:cakephp ignores form input type "number"cakephp 忽略表单输入类型“数字”
【发布时间】:2015-08-12 01:31:41
【问题描述】:

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

<?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 输入类型“数字”。 当尝试使用其他类型(如文本)时,它工作正常。 有什么想法吗?

CakePHP 版本是 2.5.4

【问题讨论】:

    标签: html cakephp-2.0 forms html-input


    【解决方案1】:

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

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

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

    【讨论】:

    • aht 字段不是表格列。它只是为了一个简单的计算。忘记说了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-16
    • 1970-01-01
    • 1970-01-01
    • 2020-06-30
    • 1970-01-01
    相关资源
    最近更新 更多