Example scaffolding
Before we dive into the details of the Forms API, we need a little scaffolding code to enable you to test the examples on a site. Here we map the URL example/page to the function call example_page(). We'll later fill this function with relevant code.
function example_menu($may_cache) {
if ($may_cache) {
$items = array();
$items[] = array(
'path' => 'example/page',
'title' => 'Example',
'callback' => 'example_page',
'access' => user_access('access example'),
'type' => MENU_CALLBACK,
);
return $items;
}
}
function example_perm() {
return array('access example');
}
/**
* This function will be called upon a visit to example/page.
*/
function example_page() {
}
The example implements the following hooks:
- hook_menu
- Maps URLs to callback functions in addition to providing a way to define actual entries in the navigation menu.
- hook_perm
- Supplies permissions that can be assigned on the admin/users/access page and checked with user_access().
To use the example code on your site, you can save it in sites/all/modules/example/example.module together with example.info:
name = Example
description = Toy with FAPI examples.