O'Reilly logo

CakePHP 1.3 Application Development Cookbook by Mariano Iglesias

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding multiple validation rules

This recipe shows how to not only use some basic validation rules provided by CakePHP, but also how to use more than one of these rules per field.

Getting ready

To go through this recipe we need a sample table to work with. Create a table named profiles using the following SQL statement:

CREATE TABLE `profiles`(
`id` INT UNSIGNED AUTO_INCREMENT NOT NULL,
`email` VARCHAR(255) NOT NULL,
`name` VARCHAR(255) default NULL,
`twitter` VARCHAR(255) default NULL,
PRIMARY KEY(`id`)
);

We proceed now to create the required model. Create the model Profile in a file named profile.php and place it in your app/models folder with the following contents:

<?php class Profile extends AppModel { public $validate = array( 'email' => array('rule' ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required