function currency_form in Currency 6
Same name and namespace in other branches
- 5 currency.module \currency_form()
- 7 currency.module \currency_form()
Currency exchange form.
1 string reference to 'currency_form'
- currency_menu in ./
currency.module - Implementation of hook_menu().
File
- ./
currency.module, line 85 - This module provides currency exchange rates.
Code
function currency_form(&$form_state) {
if (isset($form_state['values']['currency_amount']) && isset($form_state['values']['currency_from']) && $form_state['values']['currency_to']) {
// Get the saved data from the previous form submission.
$amount = $form_state['values']['currency_amount'];
$from = $form_state['values']['currency_from'];
$to = $form_state['values']['currency_to'];
$form['currency_result'] = array(
'#value' => theme('currency_result', $from, $to, $amount),
'#weight' => 5,
);
}
else {
// Get the saved data from the session, if any.
$amount = $_SESSION['currency_amount'] ? $_SESSION['currency_amount'] : 1;
$from = $_SESSION['currency_from'] ? $_SESSION['currency_from'] : variable_get('currency_default_from', 'CAD');
$to = $_SESSION['currency_to'] ? $_SESSION['currency_to'] : variable_get('currency_default_to', 'USD');
}
$form['currency_description'] = array(
'#value' => variable_get('currency_description', t('You can use this form to do currency exchange.')),
);
$form['currency_amount'] = array(
'#type' => 'textfield',
'#title' => t('Amount'),
'#default_value' => $amount,
'#size' => 9,
'#maxlength' => 9,
'#description' => t('Amount to convert'),
);
$form['currency_from'] = array(
'#type' => 'select',
'#title' => t('From'),
'#default_value' => $from,
'#options' => currency_api_get_list(),
);
$form['currency_to'] = array(
'#type' => 'select',
'#title' => t('To'),
'#default_value' => $to,
'#options' => currency_api_get_list(),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Convert'),
'#weight' => 10,
);
return $form;
}