Hi Grigri, your code seems work as i what i wanted it to do. thanks a lot!
On Dec 16, 4:07 pm, grigri <[email protected]> wrote: > It just so happens I was playing around with some code for exactly > this purpose. I stress that the code is proof-of-concept, and > definitely needs work and testing before being ready for prime time, > but by all means have a play: > > http://bin.cakephp.org/view/1263511817 > > This was my usage: > > class Address extends AppModel { > var $name = "Address"; > > var $actsAs = array('ConditionalValidation'); > > var $validate = array( > 'postal_code' => array( > array( > 'required' => true, > 'allowEmpty' => false, > 'rule' => '/^.+$/', > 'message' => 'You must enter a zip/postcode' > ), > array( > 'on' => 'country="UK"', > 'rule' => array('postal', null, 'uk'), > 'message' => 'You must supply a valid UK postcode' > ) > ) > ); > > } > > (Everyone must enter a zip/postcode, but if the address is a UK one > then the postcode must be a valid uk postcode.) > > The usage is simple - put an expression in the 'on' parameter. Various > operators are handled (see code). Every expression must be binary > (left op right). > > The LHS and RHS can be in the following format: > > "double-quoted string" => literal string > 12345 => literal integer > 3.1415927 => literal float > simple_field => $model->data[$model->alias][field] > other => first value extracted from $model->data with Set::extract() > > hth > grigri > > On Dec 16, 6:26 am, Markus <[email protected]> wrote: > > > if i set it required into false, would that means the secondary field > > can be empty? > > > how do i check something like this: > > > if (usesecondaryemail) > > validate secondary_email and secondary_email is not empty > > > can the validation for this specific fields be check from controller? > > > On Dec 16, 12:02 am, bingo <[email protected]> wrote: > > > > hi Markus, > > > > Within your secondary email validation criteria, set required:false > > > > $this->validate = array( > > > 'primary_email' => 'email', > > > 'secondary_email' => array( > > > 'rule' => 'email', > > > 'required' => false, > > > 'message' => 'Please provide valid email address' > > > ) > > > > ) > > > > On Dec 15, 10:55 am, Markus <[email protected]> wrote: > > > > > hello, > > > > > currently I'm creating an user input form which in it have an optional > > > > fields but that fields must be filtered too if the user give check on > > > > a checkbox, here is the example of part pf the form: > > > > > use secondary email: <checkbox> > > > > your secondary email: <input text> > > > > > what i want to do is disable the <input text> as default, when the > > > > user give check on check box, the <input text> is activated and user > > > > must fill the <input test> with a valid email address (couldn't be > > > > empty). > > > > > right now, i can do filtering on the email address using CakePHP > > > > filter, but how can i run the filter only when the user give check on > > > > "use secondary email" > > > > > if the user doesn't give check on "use secondary email" then i don't > > > > need to store the email value (it will be NULL in the database) > > > > > thank you --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
