I'm trying to put conditional validation in my form that validates a
correct CC is used depending on what CC was selected. Using the code
found at http://bakery.cakephp.org/articles/view/conditinalvalidation-behavior.
Seems to work for MC and Discover but not when I select VISA. If I
select VISA and put a wroThe Master Card number you supplied was
invalid.

Can anyone help?

In my Order model:

var $validate = array(
                'cc_card_number' => array(
                        'creditCardNumberRule1' => array(
                                'rule' => 'notEmpty',
                                'message' => 'Credit card number is required.'
                        ),
                        'validVisaNumber' => array(
                                'rule' => array('cc', array('visa'), false, 
null),
                                'message' => 'The Visa number you supplied was 
invalid.'
                        ),
                        'validMCNumber' => array(
                                'rule' => array('cc', array('mc'), false, null),
                                'message' => 'The Master Card number you 
supplied was invalid.'
                        ),
                        'validDiscoverNumber' => array(
                                'rule' => array('cc', array('disc'), false, 
null),
                                'message' => 'The Discover number you supplied 
was invalid.'
                        )
                ),
...

        var $actsAs = array(
                'ConditionalValidation' => array(
                        'restore' => true,
                        array(
                                'condition' => 'isCardVISA',
                                'remove' => array(
                                        array(
                                                'cc_card_number' => 
'validMCNumber',
                                                'cc_card_number' => 
'validDiscoverNumber'
                                        )
                                )
                        ),
                        array(
                                'condition' => 'isCardMC',
                                'remove' => array(
                                        array(
                                                'cc_card_number' => 
'validVisaNumber',
                                                'cc_card_number' => 
'validDiscoverNumber'
                                        )
                                )
                        ),
                        array(
                                'condition' => 'isCardDiscover',
                                'remove' => array(
                                        array(
                                                'cc_card_number' => 
'validVisaNumber',
                                                'cc_card_number' => 
'validMCNumber'
                                        )
                                )
                        )
                )
        );

    function isCardVISA()
    {
                return (($this->data['Order']['cc_card_type'] == 'VISA') ? true 
:
false);
        }

        function isCardMC()
        {
                return (($this->data['Order']['cc_card_type'] == 'MC') ? true :
false);
        }

        function isCardDiscover()
        {
                return (($this->data['Order']['cc_card_type'] == 'DISC') ? true 
:
false);
        }

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 [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