You are here

function location_proximity_form in Location 5

This function generates a form for doing proximity searches within a certain distance of a specified point.

Depending on the context within which this function is called, the search-point can either be user-supplied via the location form that is passed (if one is available) or done within a search-point extracted from a contact table or some other location source specified by the programmer calling this function.

Parameters

$prefilled_values: An associative array for prefilled values for the proximity search parameters, where 'distance' => is the prefilled int value to be selected for the distance scalar 'distance_unit' => is 'km' or 'mile'

$suppressed_values: An associative array for values you wish to force the selection of rather than pre-fill as a default. The value will be passed as a hidden form input. The passed values will be taken in as an associative array where 'distance' => a preselected positive integer for the distance 'distance_unit' => a preselected unit for the distance, one of either 'km' or 'mile'

Return value

An HTML form (generated by Drupal form functions) that lets users specify proximity search parameters that include distance, the unit of distance, and a search-point if the optional $location_form parameter is passed. If one is not passed, the caller of this function will be assumed to already have one.

1 call to location_proximity_form()
location_search_form in ./location.module

File

./location.inc, line 446

Code

function location_proximity_form($prefilled_values = array(), $suppressed_values = array()) {
  $form = array();
  if (in_array('distance', array_keys($suppressed_values))) {
    $form['distance'] = array(
      '#type' => 'hidden',
      '#value' => $suppressed_values['distance'],
    );
  }
  else {
    $form['distance'] = array(
      '#type' => 'select',
      '#default_value' => isset($prefilled_values['distance']) ? $prefilled_values['distance'] : 25,
      '#options' => drupal_map_assoc(array(
        5,
        10,
        25,
        50,
        100,
        250,
      )),
    );
  }
  if (in_array('unit', array_keys($suppressed_values))) {
    $form['unit'] = array(
      '#type' => 'hidden',
      '#value' => $suppressed_values['unit'],
    );
  }
  else {
    $form['unit'] = array(
      '#type' => 'select',
      '#default_value' => isset($prefilled_values['unit']) ? $prefilled_values['unit'] : 'mile',
      '#options' => array(
        'mile' => 'miles',
        'km' => 'km',
      ),
    );
  }
  $form['#theme'] = 'location_proximity_form';
  return $form;
}