即使您是 drupal 新手,也没有那么复杂。在这个示例中,我所要做的就是使用 hook_menu() 并了解来自 drupal form api reference 的可用表单项。
以下是您尝试做的示例。
/**
* Implementation of hook_menu()
*/
function mymodule_menu()
{
$items = array();
$items['my-custom-page-path'] = array(
'title' => 'My Page Title',
'description' => t(''),
'access callback' => 'user_access',
'access arguments' => array('access content'),
'page callback' => 'drupal_get_form',
'page arguments' => array('mymodule_form_id'),
);
return $items;
}
function mymodule_form_id($form, &$form_state)
{
$form = array();
$form['my_textfield'] = array(
'#type' => 'textfield',
'#title' => t('Text Field'),
'#description' => t(''),
'#weight' => 20,
'#required' => TRUE,
'#size' => 5,
'#maxlength' => 5,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save settings'),
'#weight' => 10000,
);
return $form;
}
/**
* Form validation callback
*/
function mymodule_form_id_validate($form, &$form_state)
{
// notice adding "_validate" to the form id
}
/**
* Form submission callback
*/
function mymodule_form_id_submit($form, &$form_state)
{
// notice adding "_submit" to the form id
}