Heine

  • Home
  • Drupal
  • About
Home » Guides » Drupal Forms API

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.
‹ Drupal Forms API up FAPI stages ›
  • Printer-friendly version

Recent posts

  • Other vectors for SA-CORE-2014-005?
  • Lazy loading: hook_hook_info is for hook owners only.
  • "Always offline" problem in EA's Origin due to antivirus
  • From bug to exploit - Bakery SSO
  • Solving getting bogus dates via MSSQL_QUERY
more

Security reviews

I provide security reviews of custom code, contributed modules, themes and entire sites.

Contact me for a quote.

Follow @Ustima

Copyright © 2014 by Heine Deelstra. All rights reserved.

  • Home
  • Drupal
  • About