Admin settings page and form boilerplate

Public

Replace MODULE_NAME with module name. Put code into MODULE_NAME.module:

</> CopyGet raw version
php
  1. /**
  2.  * Implements hook_menu().
  3.  */
  4. function MODULE_NAME_menu() {
  5. $items = array();
  6.  
  7. $items['admin/config/MODULE_NAME'] = array(
  8. 'title' => "APC",
  9. 'page callback' => 'drupal_get_form',
  10. 'page arguments' => array('MODULE_NAME_settings_form'),
  11. 'access arguments' => array('administer site configuration'),
  12. 'type' => MENU_LOCAL_TASK,
  13. 'file' => 'MODULE_NAME.admin.inc',
  14. );
  15.  
  16. return $items;
  17. }

In MODULE_NAME.admin.inc put this:

</> CopyGet raw version
php
  1. /**
  2.  * Main settings and review administration screen.
  3.  */
  4. function MODULE_NAME_settings_form($form, &$form_state) {
  5. $form = array();
  6.  
  7. $form['MODULE_NAME_title'] = array(
  8. '#type' => 'textfield',
  9. '#title' => t('Title'),
  10. '#default_value' => variable_get('MODULE_NAME_title', ''),
  11. '#description' => t('Set a default title.'),
  12. );
  13.  
  14. // Magic function which will add submit button
  15. // and make us free from writing a submit handler
  16. return system_settings_form($form);
  17. }