There are ways to deal with this, often times you need to use
different validation rules for adding a new record vs updating an
existing record. Or sometimes as an administrator you want to be able
to override the validation that is to take place.

Jonathan Snook has posted a pattern of using the multiple validations
based on the controller action that is being called. So it is very
possible to do what you are looking for.
His article is here and should get you moving in the right direction.
If its not a perfect fit, it will at least give you some ideas around
how to specify multiple validations and then select the correct
validation for the current use.
http://snook.ca/archives/cakephp/multiple_validation_sets_cakephp/


On Jun 15, 7:45 am, WhyNotSmile <sharongilmor...@gmail.com> wrote:
> Is there any way to validate on a restricted set of rules in the
> controller?
>
> For instance, I have an email address which is validated in the model
> like this:
>
> var $validate = array(
>      'email' => array(
>          'maxlength' => array(
>              'rule' => array('maxLength',100),
>              'message' => 'Email address must be 100 characters or
> less'
>           ),
>           'notEmpty' => array(
>               'rule' => 'notEmpty',
>               'message' => 'Please enter your email address'
>            ),
>           'validEmail' => array(
>               'rule' => array('email', false),
>               'message' => 'Please enter a valid email address'
>            ),
>           'unique' => array(
>               'rule' => array('isUnique', false),
>               'message' => 'This email address has already been
> registered.  If you have forgotten your password, you can get a
> reminder by clicking on the link on the login page'
>            )
>      )
> )
>
> At one point I want to validate an email address, but I don't want to
> check that it's unique (because I'm not actually saving it, just
> checking it's otherwise valid).
>
> So far I have:
>
> if($this->User->validates(array('fieldList' => array('email')))) {
>  ...
>
> }
>
> Is there any way to define which rules I want it to validate against,
> or does it have to do all of them?  I can't find anything on this in
> the validation section of the manual (using v.1.2), so any directions
> would be much appreciated.
>
> Thanks.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to