You need to create a custom validation rule.
http://book.cakephp.org/view/1179/Custom-Validation-Rules
Here's an example I have used where I need at least one of three different
fields completed (replace ModelName with your real model name):
var $validate = array(
'phone_home' => array(
'hasOnePhone' => array(
'rule' => 'hasOnePhone',
'message' => 'You must enter at least one phone number.'
)
),
'phone_work' => array(
'hasOnePhone' => array(
'rule' => 'hasOnePhone',
'message' => 'You must enter at least one phone number.'
)
),
'phone_cell' => array(
'hasOnePhone' => array(
'rule' => 'hasOnePhone',
'message' => 'You must enter at least one phone number.'
)
)
);
function hasOnePhone() {
if (
$this->data['ModelName']['phone_home'] != null
|| $this->data['ModelName'addressType]['phone_work'] != null
|| $this->data['ModelName']['phone_cell'] != null
):
return true;
endif;
return false;
}
Jeremy Burns
[email protected]
On 28 Apr 2010, at 03:20, archeons wrote:
> Is it possible to do a custom validation in cake with the conditions:
> 1. database only has 1 field lets say price
> 2. there are 3 input column price 1, 2 & 3.
> 3. I want to do validate if one of the price is inputted then that no
> error where all three no input then throw error.
>
> How to implement this?
> Do we have to create our own in view or this can be done in model even
> there is only 1 database field?
>
> Any advice is really appreciated.
>
>
> Cheers
> arch
>
> 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 [email protected]
> To unsubscribe from this group, send email to
> [email protected] For more options, visit this group at
> http://groups.google.com/group/cake-php?hl=en
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 [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en