function getdirections_direction_form in Get Directions 7.2
Same name and namespace in other branches
- 6.2 getdirections.module \getdirections_direction_form()
- 6 getdirections.module \getdirections_direction_form()
- 7.3 getdirections.module \getdirections_direction_form()
Function to setup the form
Parameters
string $fromto: Optional. The direction the supplied input applies to
string $loc: Optional. The string to search with
string $country: Optional. The country
string $latlon: Optional. Comma delimited string containing 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 469 - Fetches google map directions.
Code
function getdirections_direction_form($form, &$form_state, $fromto = '', $loc = '', $country = '', $latlon = '') {
$getdirections_defaults = getdirections_defaults();
$islocation = module_exists('location');
$isgetlocations_fields = module_exists('getlocations_fields');
if ($getdirections_defaults['use_country_dropdown'] && ($islocation || $isgetlocations_fields) && !$getdirections_defaults['advanced_autocomplete']) {
$default_country = $islocation ? variable_get('location_default_country', '') : variable_get('site_default_country', '');
$countries = array(
'#type' => 'select',
'#title' => t('Country'),
'#options' => array_merge(array(
'' => t('Please select'),
), $islocation ? _location_supported_countries() : getlocations_fields_get_countries_list()),
'#default_value' => $default_country,
);
}
$setdirections = "Drupal.getdirections.mygetDirections(); return false;";
// weights
if (getdirections_is_advanced()) {
$from_country_weight = 1;
$from_weight = 2;
$to_country_weight = 3;
$to_weight = 4;
}
else {
$from_weight = 1;
$from_country_weight = 2;
$to_weight = 3;
$to_country_weight = 4;
}
$form = array(
'#action' => '#',
'#attributes' => array(
'class' => 'getdirections_form',
'onsubmit' => $setdirections,
),
);
if ($fromto == 'from') {
$form['from'] = array(
'#type' => 'hidden',
'#value' => $latlon,
);
if (empty($loc)) {
if (empty($country)) {
$mfrom = t('Starting point');
}
else {
$mfrom = drupal_strtoupper($country);
}
}
else {
$mfrom = $loc;
}
$form['mfrom'] = array(
'#type' => 'item',
'#title' => t('From'),
'#markup' => $mfrom,
);
}
else {
$from_desc = t('Enter the address, postcode and/or city and country from where you want to start your journey.');
if (getdirections_is_advanced() && $getdirections_defaults['advanced_autocomplete']) {
$from_desc = t('Start typing the address of your starting point, then select from the dropdown menu.');
}
if ($getdirections_defaults['use_country_dropdown'] && ($islocation || $isgetlocations_fields) && !$getdirections_defaults['advanced_autocomplete']) {
$form['country_from'] = $countries;
$form['country_from']['#weight'] = $from_country_weight;
$from_desc = t('Enter the address, postcode and/or city from where you want to start your journey.');
}
$form['from'] = array(
'#type' => 'textfield',
'#title' => t('Starting from'),
'#size' => $getdirections_defaults['from_width'],
'#required' => TRUE,
'#description' => $from_desc,
'#weight' => $from_weight,
);
}
if ($fromto == 'to') {
$form['to'] = array(
'#type' => 'hidden',
'#value' => $latlon,
);
if (empty($loc)) {
if (empty($country)) {
$mto = t('Destination');
}
else {
$mto = drupal_strtoupper($country);
}
}
else {
$mto = $loc;
}
$form['mto'] = array(
'#type' => 'item',
'#title' => t('To'),
'#markup' => $mto,
);
}
else {
$to_desc = t('Enter the address, postcode and/or city and country of your journey destination.');
if (getdirections_is_advanced() && $getdirections_defaults['advanced_autocomplete']) {
$to_desc = t('Start typing the address of your destination, then select from the dropdown menu.');
}
if ($getdirections_defaults['use_country_dropdown'] && ($islocation || $isgetlocations_fields) && !$getdirections_defaults['advanced_autocomplete']) {
$form['country_to'] = $countries;
$form['country_to']['#weight'] = $to_country_weight;
$to_desc = t('Enter the address, postcode and/or city of your journey destination.');
}
$form['to'] = array(
'#type' => 'textfield',
'#title' => t('Destination'),
'#size' => $getdirections_defaults['to_width'],
'#required' => TRUE,
'#description' => $to_desc,
'#weight' => $to_weight,
);
}
$wt = 6;
if (variable_get('getdirections_use_v3', 0)) {
if ($getdirections_defaults['travelmode_show']) {
$form['travelmode'] = array(
'#type' => 'select',
'#title' => t('Travel mode'),
'#options' => array(
'driving' => t('Driving'),
'walking' => t('Walking'),
'bicycling' => t('Bicycling'),
'transit' => t('Public transport'),
),
'#default_value' => 'driving',
'#weight' => $wt,
);
$wt = $wt + 2;
if (module_exists('date_popup')) {
$form['transit_date_select'] = array(
'#type' => 'select',
'#title' => t('Date select'),
'#options' => array(
'depart' => t('Departure time'),
'arrive' => t('Arrival time'),
),
'#default_value' => 'depart',
'#prefix' => '<div id="getdirections_transit_dates_wrapper">',
'#weight' => $wt,
);
$wt = $wt + 2;
if ($getdirections_defaults['transit_date_format'] == 'int') {
$fmt = 'j/n/Y H:i';
}
else {
$fmt = 'n/j/Y H:i';
}
$form['transit_dates'] = array(
'#type' => 'date_popup',
'#default_value' => '',
'#date_year_range' => '-0:+1',
'#date_format' => $fmt,
'#mindate' => "+0",
'#suffix' => '</div>',
'#weight' => $wt,
);
$wt = $wt + 2;
}
}
if ($getdirections_defaults['travelextras_show']) {
$form['travelextras'] = array(
'#type' => 'checkboxes',
'#title' => t('Travel options'),
'#options' => array(
'avoidhighways' => t('Avoid Highways'),
'avoidtolls' => t('Avoid Tolls'),
'altroute' => t('Alternative routes'),
),
'#weight' => $wt,
);
$wt = $wt + 2;
}
}
if (getdirections_is_advanced() && $getdirections_defaults['advanced_autocomplete'] && $getdirections_defaults['waypoints'] > 0 && $getdirections_defaults['advanced_autocomplete_via'] && !$getdirections_defaults['advanced_alternate']) {
for ($ct = 1; $ct <= $getdirections_defaults['waypoints']; $ct++) {
$form['via_autocomplete_' . $ct] = array(
'#type' => 'textfield',
'#title' => t('Via !c', array(
'!c' => $ct,
)),
'#size' => $getdirections_defaults['advanced_autocomplete_via_width'],
'#weight' => $wt,
);
$wt = $wt + 2;
}
}
$getdirections_misc = getdirections_misc_defaults();
if ($getdirections_misc['trafficinfo']) {
$form['trafficinfo'] = array(
'#type' => 'markup',
'#markup' => '<input type="button" onclick="Drupal.getdirections.toggleTraffic();" title="Limited Availability" id="edit-trafficinfo" name="op" value="Toggle traffic info">',
'#weight' => $wt,
);
$wt = $wt + 2;
}
if (variable_get('getdirections_use_v3', 0)) {
if ($getdirections_misc['bicycleinfo']) {
$form['bicycleinfo'] = array(
'#type' => 'markup',
'#markup' => '<input type="button" onclick="Drupal.getdirections.toggleBicycle();" title="Limited Availability" id="edit-bicycleinfo" name="op" value="Toggle bicycling info">',
'#weight' => $wt,
);
$wt = $wt + 2;
}
if ($getdirections_misc['transitinfo']) {
$form['transitinfo'] = array(
'#type' => 'markup',
'#markup' => '<input type="button" onclick="Drupal.getdirections.toggleTransit();" title="Limited Availability" id="edit-transitinfo" name="op" value="Toggle Public transport">',
'#weight' => $wt,
);
$wt = $wt + 2;
}
if ($getdirections_misc['panoramio_show']) {
$form['panoramio'] = array(
'#type' => 'markup',
'#markup' => '<input type="button" onclick="Drupal.getdirections.togglePanoramio();" id="edit-panoramio" name="op" value="Toggle Panoramio">',
'#weight' => $wt,
);
$wt = $wt + 2;
}
}
if ($getdirections_misc['switchfromto'] && !$fromto && !getdirections_is_advanced()) {
$form['switchfromto'] = array(
'#type' => 'markup',
'#markup' => '<input type="button" onclick="Drupal.getdirections.toggleFromto();" id="edit-switchfromto" name="op" value="Switch From/To">',
'#weight' => $wt,
);
$wt = $wt + 2;
}
if (getdirections_is_advanced()) {
$form['next'] = array(
'#type' => 'button',
'#value' => t('Next'),
'#attributes' => array(
'onclick' => 'Drupal.getdirections.nextbtn(); return false;',
),
'#weight' => $wt,
);
$wt = $wt + 2;
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Get Directions'),
'#weight' => $wt,
);
return $form;
}