it's just gone 9am down here in NZ :)

you can deinfe the functions in /app/app_model.php if you think they
will be used by multiple models e.g. unique. or you can place them in
the particular model that requires that validation method
/app/models/example_model.php.

i've changed the validation a little bit and i actually pass the data
array to be validated to the loadValidation function. if nothing is
passed then i fall back on the $_POST array. so, using this method you
could pass data from multiple objects and use that for your
validation.

so within your controller you can grab data from multiple models and
pass it to your loadValidation method of your model. then use that
data in your validation methods.

do you know what i mean?

By the way, someone correct me if this is bad coding practice. I just
had some instances when information to be validated was not in the
$_POST array.

cheers,
freedom

On 23/08/06, Ámon Tamás <[EMAIL PROTECTED]> wrote:
>
> midnight mate :)
>
> (because in here in Budapest now is midnight)
>
> Mikee Freedom írta:
> > morning mate,
> >
> > As a starting point, have a look at this tutorial on the wiki:
> >
> > http://wiki.cakephp.org/tutorials:advanced_validation
> >
> > Fromhere I've been able to modify this validation method to my own
> > devices. You can pretty much define multiple validation methods for
> > each input and create the functions yourself.
> >
> > I've put some of the common ones in my app_model (unique, maxlength,
> > minlegth, etc) and others that are Model specific would stay in that
> > particular Model.
> >
> > An example of the validation array could be:
> >
> >     function loadValidation()
> >     {
> >         $this->validate = array(
> >             'email_address' => array(
> >                 'required' => array(
> >                     'method' => VALID_NOT_EMPTY,
> >                     'message' => 'Please enter an Email Address.',
> >                 ),
> >                 'unique' => array(
> >                     'method' => 'unique',
> >                     'message' => 'Your Email Address is already in our
> > records.',
> >                     'parameters' => array('email_address',
> > $_POST['data'][$this->name]['email_address'])
> >                 ),
> >                 'email' => array(
> >                     'method' => VALID_EMAIL,
> >                     'message' => 'Please enter a valid Email Address.',
> >                 )
> >             )
> >         );
> >     }
> >
> > You have to put it in this loadValidation function (within your model)
> > and call it prior to any validation check (PHP 4 issue). If you have a
> > look I have told my User model that when accepting an email address it
> > has to be not empty, unique and a valid email. The unique function I
> > grabbed also from the wiki (thankyou to the author who I can't
> > remember at this time) and other functions i have written myself.
> >
> Where can I put this functions? To this model? Or where?
> > use the invalidFields function from the tutorial, and define your own
> > validation function to check the password and the username. you can
> > see in the array that you are able to pass parameters to your defined
> > functions from the $_POST array. the validation function simply
> > returns true or false based on these parameters.
> >
> It was only an example the username and password, it  is a little bit
> difficultest. I like to use some other tables (models?) in this model
> what is not contact with fields to this. This some global rules. How can
> I make it easier?
> > if you need any further clarification let me know.
> >
> > cheers,
> > freedom
> >
> > On 23/08/06, Ámon Tamás <[EMAIL PROTECTED]> wrote:
> >
> >> Hello,
> >>
> >> How can I validate 2 fields? for example I have a username and a
> >> password, and I like to validate this two filelds are not the same?
> >>
> >> --
> >> Tamas Amon
> >>
> >
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to