Saturday, September 25, 2010

Re: how to use required => true in multiple validation

@jeremy: you can use em for the last part as well (maybe you will add
another rule some day..) - doesnt hurt anyway

actually i use this sort oder:
going from simple to more complicated! why should you check
"unique" (database query!) before notEmpty? why should you check an
email address exists in the database if it is invalid anyway. so the
order seems to be pretty self-explanatory to me :) usually that means
that the most likely ones to fail are at the beginning, of course.


On 25 Sep., 14:49, Jeremy Burns | Class Outfit
<jeremybu...@classoutfit.com> wrote:
> Yup - agreed. I always use 'last' => true for each rule in a multi-part rule array (except for the last part of course) and put them in the most sensible processing order from a user perspective - which probably means the most likely one to fail first or perhaps the most important rule.
>
> Jeremy Burns
> Class Outfit
>
> jeremybu...@classoutfit.comhttp://www.classoutfit.com
>
> On 25 Sep 2010, at 13:47, euromark wrote:
>
>
>
> > jeremy is right
> > @seehttp://www.dereuromark.de/2010/09/21/saving-model-data-and-security/
> > (The myth about "required" and "allowEmpty") further down
>
> > i would - in your case - suggest to use "last"=>true as well!
>
> > On 25 Sep., 14:25, Jeremy Burns | Class Outfit
> > <jeremybu...@classoutfit.com> wrote:
> >> I'm prepared to be corrected, but my understanding is that 'required => true' just means that the field must be present in the data array, and doesn't really test its value. So in your case, required => true might be enough.
>
> >> Jeremy Burns
> >> Class Outfit
>
> >> jeremybu...@classoutfit.comhttp://www.classoutfit.com
>
> >> On 25 Sep 2010, at 12:20, Mariano C. wrote:
>
> >>> Reading the doc there's explained that require isn't a "pure" rule, so
> >>> I'm asking how can I use it in multiple validation per field case:
>
> >>> example:
> >>> var $validate = array
> >>>    (
> >>>            'id' => array(
> >>>                    'idRule-1' => array(
> >>>                       'rule' => 'isUnique',
> >>>                       'message' => 'id is already registered.'
> >>>                    ),
> >>>                    'idRule-1' => array(
> >>>                       'rule' => '/^[a-z0-9]{3}-([a-z0-9]{5}-){3}[a-z0-9]{4}$/',
> >>>                       'message' => 'Id field is not valid.'
> >>>                    ),
>
> >>>            )
> >>> )
>
> >>> How can I explain that ID field is required? where I can write this?
>
> >>> Second question: "allowEmpty => false" is stricter than "required =>
> >>> true"? My interpretation about allowEmpty => false is: field will be
> >>> required and empty is not allowed. Am I right? If this, I could use
> >>> allowEmpty in place of required.
>
> >>> Check out the new CakePHP Questions sitehttp://cakeqs.organdhelp others with their CakePHP related questions.
>
> >>> You received this message because you are subscribed to the Google Groups "CakePHP" group.
> >>> To post to this group, send email to cake-php@googlegroups.com
> >>> To unsubscribe from this group, send email to
> >>> cake-php+unsubscribe@googlegroups.com For more options, visit this group athttp://groups.google.com/group/cake-php?hl=en
>
> > Check out the new CakePHP Questions sitehttp://cakeqs.organd help others with their CakePHP related questions.
>
> > You received this message because you are subscribed to the Google Groups "CakePHP" group.
> > To post to this group, send email to cake-php@googlegroups.com
> > To unsubscribe from this group, send email to
> > cake-php+unsubscribe@googlegroups.com For more options, visit this group athttp://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: