开发者

Cakephp input box validation on ctp page

How do I directly input validati开发者_运维知识库on as required into input box on ctp file without going to controller or model in Cakephp?


I would use JQuery, with the Jquery Validaton plugin.

It is rather straight foreward to include and write the scripts for.

In the view (using a Users form view for the example)

<?php
echo $form->create('User', array('id'=>'UserForm'));
echo $form->input('User.name', array('class'=>'required', 'minlength'=>2));
echo $form->input('User.email', array('class'=>'required email'));
echo $form->end('Send');
echo $javascript->codeBlock('$("#UserForm").validate();', array('inline'=>true));

In the layout under the header part

echo $javascript->link('jquery-1.6.2.min.js');
echo $javascript->link('jquery.validate.min.js');

In the user controller

var $helpers = array('Html', 'Form', 'Javascript');

I did testrun the code to confirm it works.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜