名称字段验证在cakephp中不起作用

时间:2016-03-03 11:57:34

标签: cakephp cakephp-2.0

下面是我的模型功能已经在工作...... 我需要验证名称字段。

当我提交空白表格时.....表格显示输入投资组合名称。

当我在名称字段中输入数值时,表单显示输入有效的投资组合名称。

但是当我提交空白表单时,表单不会显示任何名称字段的消息。

当我在名称文本框中输入数字值并提交时,它会正确显示消息。

请帮助我使规则适用于名称字段。

所以plz建议我如何实现这个。

<?php
class Portfolio extends AppModel{
   var $name = 'Portfolio';
   var $validate = array(
            'name' => array(
            'rule' => 'notEmpty',
            'message' => "Enter portfolio name."
         ),
            'name' => array(
            'rule'    => '/^[a-zA-Z]*$/',
            'message' => "Enter valid portfolio name."
         ),
            'job_title' => array(
            'rule' => 'notEmpty',
            'message' => "Enter your quote request."
         ),
            'freight_mode'=> array(
                     'rule'=>'notEmpty',
                     'message'=>"Enter your frieght mode."
         ),
            'expected_transport_growth' => array(
            'rule' => 'notEmpty',
            'message' => "Select expected transport growth."
         ),
            'current_annual_spend' => array(
            'rule' => 'notEmpty',
            'message' => "Select current annual spend."
         ),
            'expected_annual_spend' => array(
            'rule' => 'notEmpty',
            'message' => "Select expected annual spend."
         ),
            'quotes_expiry' => array(
            'rule' => 'notEmpty',
            'message' => "Enter deadline on quote request."
         ),
             'quotes_required' => array(
            'rule' => 'notEmpty',
            'message' => "Select quote requrest required."
         ),
            'contract_start_date' => array(
            'rule' => 'notEmpty',
            'message' => "Enter contract start date." 
        ),     
   );

   /*var $belongsTo = array(
        'SupplierUquotes'   => array(
        'className'     => 'SupplierUquotes',
        'foreignKey'    => 'id'
    ),);*/


  }
?>

2 个答案:

答案 0 :(得分:0)

试试这个

<?php
public $validate = array(
    'name' => array(
        'notEmpty' => array(
            'rule' => 'notEmpty',
            'message' => "Enter portfolio name."
        ),
        'valid' => array(
            'rule' => '/^[a-zA-Z]*$/',
            'message' => "Enter valid portfolio name."
        )
    )
);
?>

答案 1 :(得分:0)

试试这段代码:

for (var i in sortedCards) {
    var cardElem = sortedCards[i].element.clone();
    cardElem.appendTo($(cols[curCol]));
    sortedCards[i].element.detach()
    curCol = (curCol + 1) % numCols;
}