Hi,

I have multi record form with email addresses. I want only the first
email field to be required and second not. To achieve that I would
like to use Cake's automatic validation.

In the view I have this:

echo $this->Form->input("Email.0.email", array('label' => 'Primary
Email: '));
echo $this->Form->input("Email.1.email", array('label' => 'Secondary
Email: '));

In the Email model there is validation rule:

                'email' => array(
                        'email' => array(
                                'rule' => array('email'),
                                'message' => 'Email address is incorrect',
                        ),
                        'notempty' => array(
                                'rule' => array('notempty'),
                                'message' => 'Email address is required',
                        ),
                ),

I want Cake to validate only the first occurrence of the field during
saveAll() in the controller. Also I want to have '*' sign near the
label in the view only for Primary Email.

I know that while writing this email I can either tweak it somehow or
just disable automatic validation and validate it manually.
But wouldn't be such functionality helpful in Cake?
 - by saying $model->validateByIndex(array(0)) that validates only
$this->data['Email'][0]
 - or simply extending $validation attribute in Model for the email
field with 'index' => 0 or 'index' => array(0, 1, 2)

Does anybody have some magical solution for this? How would you solved
this?

Thanks,
Ladislav

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to