Tuesday, November 25, 2008

Re: Validation Question/Form Question

first you need allowEmpty => true for your radio buttons
then, you simply need a custom validation rule for the 'other' field

'other => array('rule'=>array('checkOther'));

function checkOther() {
if(///check if radio buttons are empty && 'other' is not decimal///)
{
return false;
}

return true;
}

On Nov 25, 3:07 pm, rgreenphotodesign <rgr...@rgreenphotography.com>
wrote:
> I find myself a little stumped on this one, maybe some can offer some
> insight.
>
> I need a "donate" form that will be sent via SSL to our merchant
> processing facility. I need a set of radio buttons that have a
> suggested donation amount (accomplished using form->radio('Amount',
> array('1000.00' =>'$1000', '500.00' => '$500', '250.00' => '$250',
> '100.00' => '$100', '54.00' => '$54', '36.00' => '$36'), null, array
> ());)
>
> But I also need a text input for other amount.
>
> So how do I validate that either a radio was selected, or an correctly
> formatted (10.00) amount is entered in other amount?
>
> I currently have :
>
> 'Amount' => array(
>                 'notEmpty' => array(
>                         'rule' => 'notEmpty',
>                         'message' => 'Please select a donation amount.')
>          ),
>
>         'Other' => array(
>                 'decimal' => array(
>                         'rule' => array('decimal', 2),
>                         'message' => 'Please include a full amount with cents.')
>          ),
>
> or do I decide what to send to validate prior to sending it in my
> controller?
>
> Hope that makes sense.
>
> Thanks for any help!!
--~--~---------~--~----~------------~-------~--~----~
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: