I am working for a client integrating authorize.net with ECHECK capabilities and in my form have a radio button that selects whether the customer wants to do a transaction with a credit card or direct debit.

The problem is, I have both fieldsets showing all the time, and I would like to only show the fieldset for the credit card entry when that is chosen and only the fieldset for direct debit when ECHECK is chosen.

I am not really sure how to move forward on this, whether AHAH can / should handle this or if I should embed JQUERY into the form element.

If anyone can point me in the right direction that would be wonderful.

$montharray = array('01','02','03','04','05','06','07','08','09','10','11','12');
	$yeararray = array('09','10','11','12','13','14','15','16','17','18','19','20');

	$form['amount'] = array(
		'#title' => t('Amount to load'),
		'#type' => 'textfield',
		'#size' => 6,
		'#weight' => -2,
		);
	$form['customer_info'] = array(
		'#type' => 'fieldset',
		'#title' => t('Billing Info'),
		'#weight' => 0,
		);
	$form['customer_info']['first_name'] = array(
		'#title' => t('Your First Name'),
		'#type' => 'textfield',
		'#description' => t('Please enter your first name.'),
		);
	$form['customer_info']['last_name'] = array(
		'#title' => t('Your Last Name'),
		'#type' => 'textfield',
		'#description' => t('Please enter your last name.'),
		);
	$form['customer_info']['address'] = array(
		'#title' => t('Address'),
		'#type' => 'textfield',
		'#description' => t('Please enter the billing address'),
		);
	$form['customer_info']['city'] = array(
		'#title' => t('City'),
		'#type' => 'textfield',
		'#description' => t('Please enter the city.'),
		);
	$form['customer_info']['state'] = array(
		'#title' => t('State'),
		'#type' => 'select',
		'#options' => array(
								'AL'=>"Alabama",
                'AK'=>"Alaska", 
                'AZ'=>"Arizona", 
                'AR'=>"Arkansas", 
                'CA'=>"California", 
                'CO'=>"Colorado", 
                'CT'=>"Connecticut", 
                'DE'=>"Delaware", 
                'DC'=>"District Of Columbia", 
                'FL'=>"Florida", 
                'GA'=>"Georgia", 
                'HI'=>"Hawaii", 
                'ID'=>"Idaho", 
                'IL'=>"Illinois", 
                'IN'=>"Indiana", 
                'IA'=>"Iowa", 
                'KS'=>"Kansas", 
                'KY'=>"Kentucky", 
                'LA'=>"Louisiana", 
                'ME'=>"Maine", 
                'MD'=>"Maryland", 
                'MA'=>"Massachusetts", 
                'MI'=>"Michigan", 
                'MN'=>"Minnesota", 
                'MS'=>"Mississippi", 
                'MO'=>"Missouri", 
                'MT'=>"Montana",
                'NE'=>"Nebraska",
                'NV'=>"Nevada",
                'NH'=>"New Hampshire",
                'NJ'=>"New Jersey",
                'NM'=>"New Mexico",
                'NY'=>"New York",
                'NC'=>"North Carolina",
                'ND'=>"North Dakota",
                'OH'=>"Ohio", 
                'OK'=>"Oklahoma", 
                'OR'=>"Oregon", 
                'PA'=>"Pennsylvania", 
                'RI'=>"Rhode Island", 
                'SC'=>"South Carolina", 
                'SD'=>"South Dakota",
                'TN'=>"Tennessee", 
                'TX'=>"Texas", 
                'UT'=>"Utah", 
                'VT'=>"Vermont", 
                'VA'=>"Virginia", 
                'WA'=>"Washington", 
                'WV'=>"West Virginia", 
                'WI'=>"Wisconsin", 
                'WY'=>"Wyoming"),
		'#description' => t('Please select your state'),
		);
	$form['customer_info']['zip'] = array(
		'#title' => t('Zipcode'),
		'#type' => 'textfield',
		'#description' => t('Please enter the zipcode'),
		);
	
		$form['transaction_type'] = array(
		'#title' => t('What payment type would you like to use?'),
		'#type' => 'radios',
		'#options' => array(
							'ECHECK' => "Direct Debit",
							'AUTH_CAPTURE' => "Credit Card",
							),
		'#weight' => 1,
		);
	
	$form['card_info'] = array(
		'#title' => t('Card Info'),
		'#type' => 'fieldset',
		'#weight' => 2,
	);
	$form['card_info']['card_number'] = array(
		'#title' => t('Card Number'),
		'#type' => 'textfield',
		'#default_value' => '4111111111111111',
		);
	$form['card_info']['exp_month'] = array(
		'#description' => t('Month'),
		'#type' => 'select',
		'#options' => 	$montharray,
		);
	$form['card_info']['exp_year'] = array(
		'#description' => t('Year'),
		'#type' => 'select',
		'#options' => $yeararray,
		'#default_value' => '15',
		);
	
	$form['bank_info'] = array(
		'#title' => 'Bank Info',
		'#type' => 'fieldset',
		'#weight' => 3,
		);
	$form['bank_info']['name_on_account'] = array(
		'#title' => "Name associated with account",
		'#type' => 'textfield',
		);
	$form['bank_info']['account_type'] = array(
		'#title' => "Type of account",
		'#type' => 'select',
		'#options' => array(
						'CHECKING' => "Checking",
						'BUSINESSCHECKING' => "Business Checking",
						'SAVINGS' => "Savings",
						),
		);
		
	$form['bank_info']['routing'] = array(
		'#title' => "Aba Routing Number",
		'#type' => 'textfield',
		'#size' => 9,
		'#maxlength' => 9,
		);
	$form['bank_info']['account_number'] = array(
		'#title' => "Account Number",
		'#type' => 'textfield',
		'#size' => 20,
		'#maxlenght' => 20,
		);
	$form['bank_info']['bank_name'] = array(
		'#title' => "Bank Name",
		'#type' => 'textfield',
		);
	
	$form['submit'] = array(
		'#type' => 'submit',
		'#value' => t('Submit'),
		'#weight' => 10,
		);

	return $form;

Comments

gdoteof’s picture

bump

lazyguy’s picture

I'm a newb but have been having good luck just searching on most of my issues -- but this one seems to be escaping me and my info searches almost completely.

I, too, would like to know the best way to collapse/hide one or more fieldsets based on the status of a checkbox or radio button group.

It seems distinctly odd that I this is just about the only post I can find on the issue. That keeps making me think I'm missing something really obvious.

Any help or insight out there?

JaredAM’s picture

There are many ways to accomplish this but personally, I'd just throw in some jquery code. You'd have to wrap your credit card fields in a div with and id that you can hide or show (or you can give those fields a class that you could hide or show).

You can add it either in your form template or in your module.

For your module:

<?php
function mymodule_init(){
  $my_js_hidder = "$(function(){
  $('#edit-transaction-type').change(function() {
    if ($(this).val() == 'ECHECK') {
      // Hide the Credit Card fields
      $('.CreditCardClass').hide('slow');
    } else {
      // Hide the Bank fields
      $('.BankClass').hide('slow');
    }
  });
  });

  drupal_add_js($my_js_hider, "inline");
}
?>

You could also stick that code in your template file.

I haven't tested that code but it should give you an idea how to do it.