Sunday, December 15, 2013

Re: Validation Question

When doing your own validation rules (which would definitely be needed here), you can access all fields on the submitted form via $this->data.

Here's an example where I validate for a PO Box on an address, if the street name is blank.

function validatePOBox($check) {
$key = current($check);
$key = key($check);
$addressType = explode('_', $key,2);
$addressType = $addressType[0];
if (empty($this->data[$this->alias][$addressType . '_street_name'])) {
return Validation::notEmpty($check[$key]);
}
return true;
}

Regards
Reuben Helms

On Sunday, 15 December 2013 01:22:17 UTC+10, advantage+ wrote:

How do you validate / invalidate 1 field based on the other.

 

Example:

User changing password I have

Confirm current (no issues there)

New Password input

Confirm New Password input

 

Now I have it set password has to be minimum 8 characters for the sake of the question.

User enters new password 15 chars, all good, then confirm is 5 chars and I get hit with 2 errors.

Different passwords entered for new password field and Password must be minimum of 8 for confirm field.

No need to have 2 error messages I would think since the new password passed validation should only be 1 message saying not the same.

 

Any ideas? Best to put all the validation rules on new password and simply check they match on the confirm field?

 

I might have answered my own question.

 

But like to know what you think.

 

Thanks,

Dave

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: