You can set it beforeValidate or beforeSave (not sure if it's called
after or before validation, I will check)

On Jul 24, 2:40 am, tyhilltx <[EMAIL PROTECTED]> wrote:
> So I can set $this->validate to different array contents (which I'm
> trying to do) but where would I call that from?  is this the
> controller method?
>
> Thanks for the input.
>
> On Jul 23, 4:16 pm, francky06l <[EMAIL PROTECTED]> wrote:
>
> > Well if you use $this->validate = array(...... ); then the validate
> > function will use the model variable ... $this->validate IS the model
> > variable used in the validation.
>
> > On Jul 23, 7:58 pm, tyhilltx <[EMAIL PROTECTED]> wrote:
>
> > > But doesn't $this->validate just call the validation using the
> > > $validate variable set in the model?  That's the variable I'm trying
> > > to set based on a session variable.  The $validate variable will
> > > contain the validate rules I want applied.
>
> > > I've run this code.  The $validate variable is getting set properly
> > > inside beforeValidate() BUT cake is not using it to validate my data.
> > > So can I not assign another array to the $validate variable?  Is that
> > > variable getting passed BEFORE beforeValidate() is being called?
>
> > > On Jul 23, 12:28 pm, francky06l <[EMAIL PROTECTED]> wrote:
>
> > > > Why not set $this->validate directly in beforeValidate of your model
> > > > (I do not see the point of the $validate variable) ?
>
> > > > On Jul 23, 7:20 pm, tyhilltx <[EMAIL PROTECTED]> wrote:
>
> > > > > I would like to set the model $validate variable based on a session
> > > > > variable that I am successfully passing into my model.  I've
> > > > > initialized the validate variable (see code below) and called it from
> > > > > within beforeValidate(). (see code below).
>
> > > > > Reason:  half of my table fields are optional based on the filing
> > > > > status the user selects.  I would like to take advantage of Cake's
> > > > > built-in validate but have these optional fields.  Will this work?  Is
> > > > > there a better alternative?
>
> > > > >     var $validate = array();
>
> > > > >         function beforeValidate() {
>
> > > > >                 global $validate;
> > > > >                 if ($this->sess_filing_status == "married") {
>
> > > > >                         $validate = array(
> > > > >                                 'user_id'  => VALID_NOT_EMPTY,
> > > > >                                 'filing_status'   => VALID_NOT_EMPTY,
> > > > >                                 'principal_first_name'   => 
> > > > > VALID_NOT_EMPTY,
> > > > >                                 'principal_last_name'   => 
> > > > > VALID_NOT_EMPTY,
> > > > >                                 'principal_county'   => 
> > > > > VALID_NOT_EMPTY,
> > > > >                                 'principal_address1'   => 
> > > > > VALID_NOT_EMPTY,
> > > > >                                 'principal_city'   => VALID_NOT_EMPTY,
> > > > >                                 'principal_state'   => 
> > > > > VALID_NOT_EMPTY,
> > > > >                                 'principal_zip'   => VALID_NOT_EMPTY,
> > > > >                                 'principal_home_phone'   => 
> > > > > VALID_NOT_EMPTY,
> > > > >                                 'principal_email'   => VALID_EMAIL,
> > > > >                                 'secondary_first_name'   => 
> > > > > VALID_NOT_EMPTY,
> > > > >                                 'secondary_last_name'   => 
> > > > > VALID_NOT_EMPTY,
> > > > >                                 'secondary_county'   => 
> > > > > VALID_NOT_EMPTY,
> > > > >                                 'secondary_address1'   => 
> > > > > VALID_NOT_EMPTY,
> > > > >                                 'secondary_city'   => VALID_NOT_EMPTY,
> > > > >                                 'secondary_state'   => 
> > > > > VALID_NOT_EMPTY,
> > > > >                                 'secondary_zip'   => VALID_NOT_EMPTY,
> > > > >                                 'secondary_home_phone'   => 
> > > > > VALID_NOT_EMPTY,
> > > > >                                 'secondary_email'   => VALID_EMAIL,
> > > > >                                 'expiration_date'   => VALID_NOT_EMPTY
> > > > >                         );
>
> > > > >                 } else {
>
> > > > >                         $validate = array(
> > > > >                                 'user_id'  => VALID_NOT_EMPTY,
> > > > >                                 'filing_status'   => VALID_NOT_EMPTY,
> > > > >                                 'principal_first_name'   => 
> > > > > VALID_NOT_EMPTY,
> > > > >                                 'principal_last_name'   => 
> > > > > VALID_NOT_EMPTY,
> > > > >                                 'principal_county'   => 
> > > > > VALID_NOT_EMPTY,
> > > > >                                 'principal_address1'   => 
> > > > > VALID_NOT_EMPTY,
> > > > >                                 'principal_city'   => VALID_NOT_EMPTY,
> > > > >                                 'principal_state'   => 
> > > > > VALID_NOT_EMPTY,
> > > > >                                 'principal_zip'   => VALID_NOT_EMPTY,
> > > > >                                 'principal_home_phone'   => 
> > > > > VALID_NOT_EMPTY,
> > > > >                                 'principal_email'   => VALID_EMAIL,
> > > > >                                 'expiration_date'   => VALID_NOT_EMPTY
> > > > >                         );
>
> > > > >                 }
>
> > > > > Thanks for your time!


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" 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