views:

829

answers:

3
A: 

place your validation logic inside beforeValidate callback.

evilbloodydemon
I can see how that would be called before each validation, but I'm struggling to see how that would help my specific case.
Pickledegg
+1  A: 

I would write a custom validation method for this purpose: http://book.cakephp.org/view/150/Custom-Validation-Rules#Adding-your-own-Validation-Methods-152

dhofstet
Pickledegg
Yes, you define a rule for one specific field, however, with $this->data you can access all data from within your validation method. So the field name is just used to trigger the validation method.
dhofstet
To dhofstet's point, you could create a Custom Validation method to loop through your $this->data['Friend'][]['name'] array and do what's necessary (return false is an email is missing, etc.)
Darren Newton
A: 

How are your fields being generated? I assume you're using something like:

<?php echo $form->input('Friend.name'); ?> [html stuff] <?php echo $form->input('Friend.email'); ?>

Since doing that several times within a page will produce duplicate ids (like, "FriendName" would be the resulting ID for each field generated by <?php echo $form->input('Friend.name'); ?>), you're probably going to have to add a number to each field name as you're generating them and then loop over $this->data['Friend'] in your controller and invalidate the offending fields as you find them (if the name is present, but the email is not, as you say).

I don't think there's a built-in way for cake to handle a situation like this, but I've been wrong before!

inkedmn
Hi inkedmn, heres how I'm generating the fields: http://pastebin.com/m44277054 As you can see they are named data[Friend][0][name] etc.
Pickledegg