Yup, you've got it right. The only improvement would be that you don't
need to give an index for each of the rules under zip.

 var $validate = array(
        'zip' => array(
           array(
                   'rule' => array('postal', null, 'us'),
                   'message' => 'Must be a valid zip code.',
                   'required' => true,'allowEmpty' => true,
                   'on' => 'create',
           ),
           array(
                  'rule' => array('postal', null, 'us'),
                  'message' => 'Must be a valid zip code.',
                  'required' => true,'allowEmpty' => false,
                  'on' => 'update',
           ),
        )
);

Works just the same.


On May 14, 10:42 pm, MikeK <[EMAIL PROTECTED]> wrote:
> I have read the posts extensively on this topic and believe I finally
> have this working the way I need it to. Just wondering if the gurus
> (yes that's you Nate!) could confirm I got it done the right way. I am
> quite excited by the richness of the 1.2 validation feature -- I'm
> removing all the ugliness I created in the controller making
> validation what I needed in the past and am trying to do it the
> 'right' way in the model only.
>
> I have a user model in which a subset of the fields are required - the
> caveat is that only a portion of the required fields are required
> during registration (on create) and the balance are required on
> updates (my activation and user profile edit actions in which the user
> inputs the rest of the required data or edits it).
>
> Not to bore you with repetitive stuff but here's how I handled my zip
> code field. Zip is not required on the create operation (Registration)
> but is later required on Updates (Activation, Edit, etc).
>
> Apologies in advance for the formatting if it is bad:
>
>  var $validate = array(
>         'zip' => array(
>                 'zip' => array(
>                         'rule' => array('postal', null, 'us'),
>                         'message' => 'Must be a valid zip code.',
>                         'required' => true,'allowEmpty' => true,
>                         'on' => 'create',
>                         ),
>                 'zip2' => array(
>                         'rule' => array('postal', null, 'us'),
>                         'message' => 'Must be a valid zip code.',
>                         'required' => true,'allowEmpty' => false,
>                         'on' => 'update',
>                         ),
>         ) // END OF ZIP VALIDATION
> );
>
> This seems to have the desired results -- is there a more efficient
> encoding of these arrays? Does it really matter what I call the array
> indices (zip and zip2)? Thanks in advance.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to