Oh cool i didnt know i could code a custom method and call it from the
validates array. Thats way better than what I've been doing (override
validates.) Thanks.


On Feb 11, 9:37 am, grigri <[email protected]> wrote:
> Here's an excerpt from a model I had for validating this sort of
> thing:
>
> class Order extends AppModel {
>   var $name = "Order";
>
>         var $validate = array(
>                 // ...
>                 'card_valid_from' => array(
>                         'on' => 'card',
>                         'allowEmpty' => false,
>                         'rule' => array('validateRelativeDate', false),
>                         'message' => 'Time travellers are not allowed to shop 
> here'
>                 ),
>                 'card_valid_to' => array(
>                         'on' => 'card',
>                         'allowEmpty' => false,
>                         'rule' => array('validateRelativeDate', true),
>                         'message' => 'That card has expired'
>                 ),
>                 // ...
>         );
>
>         function deconstruct($field, $data) {
>                 if ($field == 'card_valid_from' || $field == 'card_valid_to') 
> {
>                         $data['day'] = '01';
>                 }
>                 return parent::deconstruct($field, $data);
>         }
>
>         function validateRelativeDate($date, $inFuture) {
>                 $now = date('Y-m') . '-01';
>
>                 $date = reset($date);
>
>                 if ($inFuture) {
>                         return $date >= $now;
>                 }
>                 else {
>                         return $date <= $now;
>                 }
>         }
>
> }
>
> The view form elements look like this (excerpt):
>
> echo $form->inputs(array(
>         'legend' => 'Pay by Credit Card',
>         'card_valid_from' => array('type' => 'date', 'dateFormat' => 'MY'),
>         'card_valid_to' => array('type' => 'date', 'dateFormat' => 'MY')
> ));
>
> hth
> grigri
>
> On Feb 10, 7:38 pm, JoshSchramm <[email protected]> wrote:
>
> > Hey all,
>
> > I cant seem to find anything online to explain this so i'm hoping you
> > all can help a bit.
>
> > I am validating credit card information and right now i'm working on
> > ensuring the user enters an expiration date.
> > For this i have to fields one for month and one for year both using
> > $form->input('type'='date')
>
> > When they post the data looks like
> > [ExpirationMonth] { [month]=>XX }, [ExpirationYear] { [year]=>XXXX}
>
> > On the back end I'm trying to validate this and it doesnt want to
> > work. My validate array looks like this.
>
> > 'ExpirationMonth.month'=>array(
> >                         'numeric'=>array(
> >                                 'rule'=>'numeric',
> >                                 'allowEmpty'=>false,
> >                                 'required'=>true,
> >                                 'message'=>'ExpirationMonthInvalid'
> >                         ),
> >                         'between'=>array(
> >                                 'rule'=>array('between', 1, 12),
> >                                 'allowEmpty'=>false,
> >                                 'required'=>true,
> >                                 'message'=>'ExpirationMonthInvalid'
> >                         ),
> >                 ),
> >                 'ExpirationYear.year'=>array(
> >                         'notEmpty'=>array(
> >                                 'rule'=>'notEmpty',
> >                                 'allowEmpty'=>false,
> >                                 'required'=>true,
> >                                 'message'=>'ExpirationYearInvalid'
> >                         ),
> >                         'numeric'=>array(
> >                                 'rule'=>'numeric',
> >                                 'allowEmpty'=>false,
> >                                 'required'=>true,
> >                                 'message'=>'ExpirationYearInvalid'
> >                         )
> >                 )
>
> > no matter what i do i don't get an error message back.
>
> > To clarify a bit more i have a 'empty'=>'Choose Month (or year)' in
> > the drop downs so I'm just trying to make sure the user selected
> > something other than that option.
>
> > Any ideas?
--~--~---------~--~----~------------~-------~--~----~
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