Main Author: Ravindra de Silva Contributors: …

Location Library

Generate Location Boxes

This allows you to create a set of select boxes with AJAX capability. all you need to do is include the libray and call the API function. For AJAX to function javascript needs to be enabled at the client side.

The function to use is

  • $range is the range of location levels you want to display

i.e Though levels from Country to City exists ,you might want to display only Country to State

  • if you want to pre-select a location ,then pass a value. If you pass a city then

the State and Country will also be populated.

  • If you want to show only the locations of the Country “USA” then you can pass the

location id of USA as $parent.

  • In $extra_opts you can specify whether you want to display location unknown check box

and whether you want to display camps, organizations alongside the locations. for example if you want to show camps, then pass $extra_opts[“camps”]=true;


require_once $global['approot']."/inc/";

this will create 4 select boxes from level 1 to level 4 remember in the database in field_options, we define the levels. In addition this will generate a select box to select camps.

if you need only the first 3 levels


Then once the form is submitted ,there will a POST variable for each level. Name of the variable will be the level number.

Note: You can display both camps and organizations at the same time with locations. It will be extended to display Inventories as well.


Above code will produce two radio buttons and a set of location select boxes. When you select the “camp” radio button , a select box will appear with the camps. When you select a camp, through AJAX, location details of the camp (country,city,state,etc) will be retrieved and the location boxes will get populated with those. Similar functionality can be seen when you select the “organization” radio button.

Obtain the location selected by user from POST variables

the function to use is


This function will start from the lowest level of the select boxes (say city) and goes up the select boxes till it finds a location selected and returns it.



Other API functions


Returns true if the location does not have any children.


Returns an array of descendants of a location.


Displays the full range of location levels for the user.


Returns the list of parents of the location. Starting from the location to the parent, grand parent,etc. For each level the name and location id is returned.


Returns the level of the location.


Returns whether the location is in the last level or not.


Returns the last location level available.


Returns the range of levels available.

QR Code
QR Code dev:location_handler (generated for current page)