doulu1907 2013-04-12 06:11 采纳率: 100%
浏览 26

为什么Cakephp验证不起作用?

i have an input box like

<input id="BreakdownProgName" type="text" required="required" placeholder="customer name" size="50" name="data[Breakdown][prog_name]">

My model validation is not working for this code but when i put in replace of above code like below-

<?php echo $this->Form->input('Breakdown.prog_name',array('label'=>false,'div'=>false,'size'=>50,'placeholder'=>"customer name",'type'=>'text')); ?>

That time validation is working perfectly.but i want to use first one and also want validation works perfectly with that first code.What should i do?

My controller code is

public function qty_breakdown1() 
    {

            $this->layout='common';

        if(empty($this->data) == false)
        {

            if($this->Breakdown->save($this->data))
            {
                //echo "This";
                $this->Session->setFlash('B Added Successfully.', 'default', array('class' => 'oMsg1 oMsgError1'));
                $this->redirect('qty_breakdown');
            }

        }
        else
        {
            $this->set('errors', $this->Breakdown->invalidFields());    
        }
     }
  • 写回答

1条回答 默认 最新

  • douliang1369 2013-04-12 06:24
    关注

    Your validation should work regardless of the view code provided that field names are correct in POST data. That's because validation works on server side.

    However if you want to display validation errors you should use Cake's FormHelper to render form elements or manually check for validation errors in view file and display them from PHP code.

    Edit: Please check API: isFieldError - checks if field has error and error - renders formatted error message for given field.

    评论

报告相同问题?

悬赏问题

  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。