function getdirections_direction_form in Get Directions 6
Same name and namespace in other branches
- 6.2 getdirections.module \getdirections_direction_form()
- 7.3 getdirections.module \getdirections_direction_form()
- 7.2 getdirections.module \getdirections_direction_form()
Function to setup the form
Parameters
$direction: Optional. The direction the supplied input applies to
$location: Optional. The string to search with
$country: Optional. The country
$latlon: Optional. Comma delimted string containg latitude and longitude
Return value
Returns the form
1 string reference to 'getdirections_direction_form'
- getdirections_direction in ./
getdirections.module - Function to setup the map and form
File
- ./
getdirections.module, line 283 - Fetches google map directions.
Code
function getdirections_direction_form($form_state, $fromto = '', $loc = '', $country = '', $latlon = '') {
global $language;
$getdirections_defaults = getdirections_defaults();
$location = module_exists('location');
if (!$location) {
$setdirections = "setDirectionsfromto(this.from.value, this.to.value, this.locale.value); return false;";
}
else {
if ($fromto == 'to') {
$setdirections = "setDirectionsto(this.from.value, this.country_from.value, this.to.value, this.locale.value); return false;";
}
elseif ($fromto == 'from') {
$setdirections = "setDirectionsfrom(this.from.value, this.to.value, this.country_to.value, this.locale.value); return false;";
}
else {
$setdirections = "setDirectionsfromto2(this.from.value, this.country_from.value, this.to.value, this.country_to.value, this.locale.value); return false;";
}
$countries = array(
'#type' => 'select',
'#title' => t('Country'),
'#options' => array_merge(array(
'' => t('Please select'),
), _location_supported_countries()),
'#default_value' => variable_get('location_default_country', 'uk'),
'#prefix' => '<div class="container-inline getdirections_display">',
'#suffix' => '</div>',
);
}
$form = array(
'#action' => '#',
'#attributes' => array(
'class' => 'getdirections_form',
'onsubmit' => $setdirections,
),
);
if ($fromto == 'from') {
$form['from'] = array(
'#type' => 'hidden',
'#value' => $latlon,
);
$form['mfrom'] = array(
'#type' => 'item',
'#title' => t('From'),
'#value' => $loc . ', ' . drupal_strtoupper($country),
'#prefix' => '<div class="container-inline getdirections_display">',
'#suffix' => '</div>',
);
}
else {
$form['from'] = array(
'#type' => 'textfield',
'#title' => t('Starting from'),
'#size' => $getdirections_defaults['from_width'],
'#required' => TRUE,
'#description' => t('Enter the address, postcode and/or city from where you want to start your journey.'),
);
if ($location) {
$form['country_from'] = $countries;
}
}
if ($fromto == 'to') {
$form['to'] = array(
'#type' => 'hidden',
'#value' => $latlon,
);
$form['mto'] = array(
'#type' => 'item',
'#title' => t('To'),
'#value' => $loc . ', ' . drupal_strtoupper($country),
'#prefix' => '<div class="container-inline getdirections_display">',
'#suffix' => '</div>',
);
}
else {
$form['to'] = array(
'#type' => 'textfield',
'#title' => t('Destination'),
'#size' => $getdirections_defaults['to_width'],
'#required' => TRUE,
'#description' => t('Enter the address, postcode and/or city of your journey destination.'),
);
if ($location) {
$form['country_to'] = $countries;
}
}
if (variable_get('use_v3', 0)) {
if ($getdirections_defaults['travelmode_show']) {
$form['travelmode'] = array(
'#type' => 'select',
'#title' => t('Travel mode'),
'#options' => array(
'driving' => 'Driving',
'walking' => 'Walking',
'bicycling' => 'Bicycling',
),
'#default_value' => 'driving',
'#prefix' => '<div class="container-inline getdirections_display">',
'#suffix' => '</div>',
);
}
if ($getdirections_defaults['travelextras_show']) {
$form['travelextras'] = array(
'#type' => 'checkboxes',
'#title' => t('Travel options'),
'#options' => array(
'avoidhighways' => 'Avoid Highways',
'avoidtolls' => 'Avoid Tolls',
'altroute' => 'Alternative routes',
),
'#prefix' => '<div class="container-inline getdirections_display">',
'#suffix' => '</div>',
);
}
}
$form['locale'] = array(
'#type' => 'hidden',
'#value' => $language->language,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Get Directions'),
);
return $form;
}