Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

drupal_get_form page callback usage

Tags:

drupal

function example_menu() {
  $items['admin/config/example'] = array(
    'title' => 'Example',
    'description' => 'example configuration',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('example_admin_settings'),
    'access arguments' => array('administer example'),
    'file' => 'example.admin.inc',
    'file path' => drupal_get_path('module', 'example'),
  );
  return $items;
}

In the above code I am confused how it works. The page callback is drupal_get_form and the page arguments is example_admin_settings. My question is how exactly does this work?

I know that drupal_get_form probably ends up calling example_admin_settings which return system_settings_form. Could someone point me to the right docs?

like image 612
Chris Muench Avatar asked Nov 01 '25 21:11

Chris Muench


1 Answers

You're on the right path.

When you access admin/config/example, drupal_get_form('example_admin_settings') is executed. example_admin_settings() itself will return an array which has its contents based on the form api, something like:

$form['name'] = array(
    '#type' => 'input',
    '#title' => 'Insert your name here: ',
);
$form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Submit',
);

return $form;

Drupal will render and output the form automatically for you.
Also, consider posting your next questions about Drupal at https://drupal.stackexchange.com/.

like image 117
acm Avatar answered Nov 03 '25 19:11

acm