Scenario Combinations and Validating Multiple Types of Shipping Addresses

I’m posting in hopes that someone else has run into a similar scenario (no pun intended)…

I have a checkout page that requires the user to input a number of fields. However, validation is not straightforward as there are two main scenario groups:

[list=1]

[*]whether or not the user chooses to enter CC informaion

[*]whether or not the shipping address is international

[/list]

Because of this, there are 4 possible combinations (scenarios):

[list=1]

[*]the user enters CC and is domestic address

[*]the user enters CC and is international address

[*]the user doesn’t enter CC and is domestic address

[*]the user doesn’t enter CC and is international address

[/list]

Is the most efficient way to tackle this by creating 4 different scenarios and then applying rules to the appropriate combinations of them?

For example:




public function rules()

{

  return array(

    // Domestic address rules

    array('usAddr1,usAddr2,usCity,usState,usZip', 'required', 'on'=>'CCDom,noCCDom');


    // International address rules

    array('intlAddr1,intlAddr2,intlAddr3,intlCity,intlPostalCode', 'required', 'on'=>'CCIntl,noCCIntl');


    // CC entered rules

    array('CCNumber,CCExp,CCName,CCAddr', 'required', 'on'=>'CCDom,CCIntl');


    // noCC entered rules

    array('phone', 'required', 'on'=>'noCCDom,noCCIntl');

  );

}



What if there were more scenario groups? The combinations could get unwieldy, right? Consider the case where I wanted to customize the checkout such that the address fields were validated on a per-country basis… If I have 3 countries and two possible billing methods that means I’d have 6 unique scenarios!

Good luck! I have a similar problem and it seems there is no easy way out. I use JS to hide the un-neccesary fields and create the label text manually to add the required stars - this isnt perfect but it sortof works!

I raised a similar issue here.