Skip to content

Instantly share code, notes, and snippets.

@LarsEliasNielsen
Last active August 29, 2015 13:57
Show Gist options
  • Save LarsEliasNielsen/9367734 to your computer and use it in GitHub Desktop.
Save LarsEliasNielsen/9367734 to your computer and use it in GitHub Desktop.
Drupal 7 Module Development: Config form
<?php
/**
* Implements hook_form().
*
* Creates a configuration form. See the API reference for info on different
* form inputs.
*
* From API Reference: https://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7
*
* @url: https://api.drupal.org/api/drupal/modules!node!node.api.php/function/hook_form/7
*/
function espn_news_form($form, &$form_state) {
// Fieldset.
$form['espn_api'] = array(
'#type' => 'fieldset',
'#title' => t('ESPN API'),
'#weight' => 0,
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
// Textfield for API key.
$form['espn_api']['espn_news_api_key'] = array(
'#type' => 'textfield',
'#title' => t('ESPN API key'),
'#default_value' => variable_get('espn_news_api_key'),
'#size' => 40,
'#maxlength' => 24,
'#description' => t('API from ESPN Developer Center (http://developer.espn.com/apps/mykeys).'),
'#required' => TRUE,
);
return system_settings_form($form);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment