我正在尝试在 Drupal 6 中编写一个自定义模块,并尝试使用表单 API 在管理区域中添加一个简单的表单。
我已经显示了表单,但在提交然后重新加载页面时似乎无法再次填充自己。我尝试将 &$form_state 的第二个参数传递给我的 hook_form 函数,但它会导致关于缺少第二个参数的错误。
我确定这很简单,但我不太明白,这是我的 .module 代码:
/*
* Implements hook_init().
*/
function movehub_featured_links_block_init() {
drupal_add_css(drupal_get_path('module', 'movehub_featured_links_block') . '/assets/css/movehub-featured-links-block-style.css');
}
/**
* Implements hook_theme().
*/
function movehub_featured_links_block_theme() {
return array(
'movehub_featured_links_block_manage' => array(
'template' => 'movehub-featured-links-block-admin-manage'
),
'movehub_featured_links_block_add' => array(
'template' => 'movehub-featured-links-block-admin-add',
'arguments' => array('link_id' => null)
),
);
}
function movehub_featured_links_block_manage() {
return theme('movehub_featured_links_block_manage');
}
function movehub_featured_links_block_add_form(&$form) {print_r($form);
$form = array();
$form['#attributes'] = array('enctype' => 'multipart/form-data');
$form['link_title'] = array(
'#type' => 'textfield',
'#title' => t('Link Title')
);
$form['image'] = array(
'#type' => 'file',
'#title' => t('Image')
);
$form['image_hover'] = array(
'#type' => 'file',
'#title' => t('Hover Image')
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Add!')
);
return $form;
}
/**
* Implements hook_menu().
*/
function movehub_featured_links_block_menu() {
$items = array();
$items['admin/featured_links'] = array(
'title' => 'Featured Links',
'description' => 'Add, view and edit featured links..',
'page callback' => 'movehub_featured_links_block_manage',
'page arguments' => array('movehub_featured_links_block_admin'),
'access arguments' => array('administer movehub_featured_links_block settings'),
'type' => MENU_NORMAL_ITEM,
);
$items['admin/featured_links/manage'] = array(
'title' => 'Manage',
'description' => 'Add, view and edit featured links.',
'page callback' => 'movehub_featured_links_block_manage',
'page arguments' => array('movehub_featured_links_block_admin'),
'access arguments' => array('administer movehub_featured_links_block settings'),
'type' => MENU_NORMAL_ITEM,
);
$items['admin/featured_links/add'] = array(
'title' => 'Add',
'description' => 'Add a new featured link.',
'page callback' => 'drupal_get_form',
'page arguments' => array('movehub_featured_links_block_add_form'),
'access arguments' => array('administer movehub_featured_links_block settings'),
'type' => MENU_CALLBACK
);
return $items;
}
function movehub_featured_links_block_add_form_submit($form, &$form_state) {
}
function movehub_featured_links_block_add_form_validation($form, &$form_state) {
}