| 1 |
<?php |
<?php |
| 2 |
// $Id: ahah_helper_demo.module,v 1.1 2008/08/29 18:58:21 wimleers Exp $ |
// $Id: ahah_helper_demo.module,v 1.2 2008/11/19 16:25:29 wimleers Exp $ |
| 3 |
|
|
| 4 |
|
|
| 5 |
//---------------------------------------------------------------------------- |
//---------------------------------------------------------------------------- |
| 31 |
|
|
| 32 |
ahah_helper_register($form, $form_state); |
ahah_helper_register($form, $form_state); |
| 33 |
|
|
| 34 |
|
// We remember the last company used, to restore it when a user switched to |
| 35 |
|
// Personal usage and back to Company usage. |
| 36 |
|
if (isset($form_state['values']['billing_info']['company_name'])) { |
| 37 |
|
$form_state['storage']['billing_info']['company_name'] = $form_state['values']['billing_info']['company_name']; |
| 38 |
|
} |
| 39 |
|
|
| 40 |
$form['billing_info'] = array( |
$form['billing_info'] = array( |
| 41 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 42 |
'#title' => t('Billing information'), |
'#title' => t('Billing information'), |
| 51 |
'private' => t('Private'), |
'private' => t('Private'), |
| 52 |
'company' => t('Company'), |
'company' => t('Company'), |
| 53 |
), |
), |
| 54 |
'#default_value' => $form_state['values']['billing_info']['usage'], |
'#default_value' => 'company', |
| 55 |
'#ahah' => array( |
'#ahah' => array( |
| 56 |
'event' => 'change', |
'event' => 'change', |
| 57 |
// This is the "magical path". Note that the parameter is an array of |
// This is the "magical path". Note that the parameter is an array of |
| 74 |
|
|
| 75 |
|
|
| 76 |
// If 'company' is selected, then these two form items will be displayed. |
// If 'company' is selected, then these two form items will be displayed. |
| 77 |
if ($form_state['values']['billing_info']['usage'] == 'company') { |
if (!isset($form_state['values']) || $form_state['values']['billing_info']['usage'] == 'company') { |
| 78 |
$form['billing_info']['company_name'] = array( |
$form['billing_info']['company_name'] = array( |
| 79 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 80 |
'#title' => t('Company name'), |
'#title' => t('Company name'), |
| 81 |
'#required' => TRUE, |
'#required' => TRUE, |
| 82 |
'#size' => 20, |
'#size' => 20, |
| 83 |
'#maxlength' => 255, |
'#maxlength' => 255, |
| 84 |
'#default_value' => $form_state['values']['billing_info']['company_name'], |
// If the user switched to Private usage and back to Company usage, we |
| 85 |
|
// remembered his company's name! |
| 86 |
|
'#default_value' => (isset($form_state['storage']['billing_info']['company_name'])) ? $form_state['storage']['billing_info']['company_name'] : '', |
| 87 |
); |
); |
| 88 |
$form['billing_info']['vat'] = array( |
$form['billing_info']['vat'] = array( |
| 89 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 91 |
'#description' => t('Please enter a Belgian VAT number, the format is: <em>BE0999999999</em>.'), |
'#description' => t('Please enter a Belgian VAT number, the format is: <em>BE0999999999</em>.'), |
| 92 |
'#size' => 20, |
'#size' => 20, |
| 93 |
'#maxlength' => 255, |
'#maxlength' => 255, |
|
'#default_value' => $form_state['values']['billing_info']['vat'], |
|
| 94 |
'#ahah' => array( |
'#ahah' => array( |
| 95 |
'event' => 'blur', |
'event' => 'blur', |
| 96 |
'path' => ahah_helper_path(array('billing_info', 'vat')), |
'path' => ahah_helper_path(array('billing_info', 'vat')), |
| 111 |
'#required' => TRUE, |
'#required' => TRUE, |
| 112 |
'#size' => 20, |
'#size' => 20, |
| 113 |
'#maxlength' => 255, |
'#maxlength' => 255, |
|
'#default_value' => $form_state['values']['billing_info']['first_name'], |
|
| 114 |
); |
); |
| 115 |
$form['billing_info']['last_name'] = array( |
$form['billing_info']['last_name'] = array( |
| 116 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 118 |
'#required' => TRUE, |
'#required' => TRUE, |
| 119 |
'#size' => 20, |
'#size' => 20, |
| 120 |
'#maxlength' => 255, |
'#maxlength' => 255, |
|
'#default_value' => $form_state['values']['billing_info']['last_name'], |
|
| 121 |
); |
); |
| 122 |
} |
} |
| 123 |
|
|
| 127 |
'#required' => TRUE, |
'#required' => TRUE, |
| 128 |
'#size' => 20, |
'#size' => 20, |
| 129 |
'#maxlength' => 255, |
'#maxlength' => 255, |
|
'#default_value' => $form_state['values']['billing_info']['address'], |
|
| 130 |
); |
); |
| 131 |
$form['billing_info']['country'] = array( |
$form['billing_info']['country'] = array( |
| 132 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 133 |
'#title' => t('Country'), |
'#title' => t('Country'), |
| 134 |
'#size' => 20, |
'#size' => 20, |
| 135 |
'#maxlength' => 255, |
'#maxlength' => 255, |
|
'#default_value' => $form_state['values']['billing_info']['country'], |
|
| 136 |
); |
); |
| 137 |
|
|
| 138 |
$form['save'] = array( |
$form['save'] = array( |