Re: QuickForm Custom Rule Question
| From: | batterhead | Date: | Tue, 04 Dec 2007 12:26:22 +0000 |
| Subject: | Re: QuickForm Custom Rule Question | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-28262@lists.php.net to get a copy of this message | ||
Dan,
That does look a lot cleaner :) Thank you for pointing this out.
- B
On Dec 4, 2007 12:30 AM, Hollenbeck, Dan <dan.h@thoughtfulhouse.org> wrote:
>
>
>
> Try coding it using addFormRule() - it is cleaner.
>
> http://pear.php.net/manual/en/package.html.html-quickform.html-quickform.addformrule.php
>
> // Require Database
> require("Validate/Finance/CreditCard.php");
>
> // callback function for credit card validation
> function validCCNum($fields) {
> $ccType = $fields['gcCCType'];
> $ccNum = $fields['gcCCNum'];
>
> if($result = Validate_Finance_CreditCard::number($ccNum, $ccType)){
> return array('gcCCNum'=>'Credit Card Number is Not Valid')
> }else {
> return true;
> }
> }
>
> $form->addElement('select', 'gcCCType', 'CC Type:', $cc);
> $form->addElement('text', 'gcCCNum', 'CC Number:',
> array('size' => 25,
> 'maxlength' => 25));
> $form->addFormRule('validCCNNum');
>
> ________________________________
> From: batterhead [mailto:batterhead@gmail.com]
> Sent: Mon 12/3/2007 10:24 PM
> To: pear-general@lists.php.net
> Subject: [PEAR] QuickForm Custom Rule Question
>
>
>
>
>
> Hi all,
>
> I am using a custom rule to check a credit card number with the
> Validate package. I know validation function works because I tested
> outside the form.
>
> I am just not sure how to properly call it even though I have been
> studying the examples... It just don't work. Any help would be
> appreciated.
>
> // Require Database
> require("Validate/Finance/CreditCard.php");
>
> // callback function for credit card validation
> function validCCNum($card) {
> $ccType = $card[0];
> $ccNum = $card[1];
>
> $result = Validate_Finance_CreditCard::number($ccNum, $ccType);
> return $result;
> }
>
>
> $form->addElement('select', 'gcCCType', 'CC Type:', $cc);
> $form->addElement('text', 'gcCCNum', 'CC Number:',
> array('size' => 25,
> 'maxlength' => 25));
>
> $form->registerRule('validatecc', 'callback', 'validCCNum');
> $form->addRule(array('gcCCType','gcCCNum'), 'Credit Card Number is
> Not
> Valid', 'validatecc', 'client');
>
> Thanks!
>
> --
>
> PEAR General Mailing List (http://pear.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>