If statement to display different sections of form
Posted: Fri Sep 17, 2010 9:11 pm
Hi,
I have created a form. When the user selects New Zealand from the country menu I would like the form to display a new field called 'city' and when a user selects a field outside of New Zealand I would like to display a new field called eligibility to work in New Zealand.
The code for the country section of the form (Note, I won't list all countries as it will be a very long piece of code.
The if statement and 'city' code
else statement and eligibility to work in NZ code
Thanks,
Dan
I have created a form. When the user selects New Zealand from the country menu I would like the form to display a new field called 'city' and when a user selects a field outside of New Zealand I would like to display a new field called eligibility to work in New Zealand.
The code for the country section of the form (Note, I won't list all countries as it will be a very long piece of code.
Code: Select all
$form['job_posting_country'] = array(
'#type' => 'select',
'#title' => t('Country'),
'#default_value' => variable_get('feed_item_length','New Zealand'),
'#required' => True,
'#options' => array(
'New Zealand' => ('New Zealand'),
'Australia' => ('Australia'),
'Afghanistan' => ('Afghanistan'),
'Albania' => ('Albania'),
'Algeria' => ('Algeria'),
'American Samoa' => ('American Samoa'),
'Andorra' => ('Andorra'),
),
'#description' => t('Select the country you currently live in'),
);
Code: Select all
if ($form['job_posting_country'] == 'New Zealand'){
$form['job_posting_region'] = array(
'#type' => 'select',
'#title' => t('Region'),
'#default_value' => variable_get('feed_item_length','Northland'),
'#required' => TRUE,
'#options' => array (
'Northland' => t('Northland'),
'Auckland' => t('Auckland'),
'Coromandel' => t('Coromandel'),
'Waikato' => t('Waikato'),
'Bay of Plenty' => t('Bay of Plenty'),
'East Coast' => t('East Coast'),
'Central Plateau' => t('Central Plateau'),
'Hawkes Bay' => t('Hawkes Bay'),
'Taranaki' => t('Taranaki'),
'Manawatu-Wanganui'=> t('Manawatu-Wanganui'),
'Wairarpa' => t('Wairarpa'),
'Wellington' => t('Wellington'),
'Nelson' => t('Nelson'),
'Marlborough' => t('Marlborough'),
'West Coast' => t('West Coast'),
'Canterbury' => t('Canterbury'),
'Otago' => t('Otago'),
'Southland' => t('Southland'),
),
'#description' => t('Select the region you currently live in'),
);
}
Code: Select all
else {
$form['job_posting_workinnz'] = array(
'#type' => 'radios',
'#title' => t('Entitled to work in New Zealand'),
'#requited' => TRUE,
'#default_value' => variable_get('comment_preview', 1),
'#options' => array(t('I have a work permit'), t('I require a work permit')),
);
}
Dan