Alright, well I solved my own problem. It might not be the most
efficient method, but given that I didn't find anything within CakePHP
to handle this, I think it's pretty good. In case anyone else is
looking for how to do it, here's what I did. Within app_model.php,
simply create the following function:
/**
* Name: validates()
* Desc: Allow only specified fields to be validated for a model.
*/
function validates($fieldList = null) {
// If no fields are specified, then simply use the standard
validation method.
if ($fieldList === null) {
return parent::validates();
} else {
// If a single value is passed as a string, convert it to an
array.
if (!is_array($fieldList)) {
$fieldList = array($fieldList);
}
// If the validation array is not set for the model, then there
is
nothing to check.
if (!isset($this->validate) || empty($this->validate)) {
return true;
} else {
// Create a placeholder for the original validation
array, then
filter out
// any fields that do not require validation. Perform
the
validation, then
// restore the original validation array for the model.
$validate = $this->validate;
$this->validate = array_intersect_key($this->validate,
array_flip($fieldList));
$result = parent::validates();
$this->validate = $validate;
return $result;
}
}
}
Now, when you want to validate specific fields, just pass an array of
field names to the validates() function.
$this->Member->set($this->data);
$result = $this->Member->validates(array('password', 'password2'));
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---