【发布时间】:2014-04-03 08:32:22
【问题描述】:
我对 Drupal 还很陌生,刚刚制作了我的第一个模块,它显示了一个表单。在 hook_menu() 中,我设置了 $items['form'],如下所示。当我导航到 mysite.com/form 时,它没有显示任何内容,除了主题和:找不到页面,找不到请求的页面“/form”。
我试图清除我的缓存,给我的模块一个不同的名称,确保我的模块已启用,但没有任何帮助。有谁知道问题可能是什么? .module 文件中的代码就在这里:
<?php
//implements hook_permission()
function form_example_permission() {
return array(
'Submit form_example' => array(
'title' => t('Submit form_example'),
'description' => t('Submit the form_example form'),
),
);
}
//implements hook_menu()
function form_example_menu() {
$items['form'] = array(
'title' => 'My Example Form',
'type' => MENU_NORMAL_ITEM,
'acces' => TRUE,
'page callback' => 'drupal_get_form()',
'page arguments' => array('form_example_form'),
'acces arguments' => array('acces content'),
);
return $items;
}
//implements hook_form()
function form_example_form($form, &$form_state) {
$form['mynumber'] = array (
'#type' => 'textfield',
'#title' => t('My Number'),
'#size' => 10,
'#maxlength' => 10,
'#required' => TRUE,
'#description' => t('Please enter a valid number'),
);
$form['mytextfield'] = array(
'#type' => 'textfield',
'#title' => t('My Textfield'),
'#size' => 60,
'#maxlength' => 128,
'#required' => TRUE,
);
$form['mytext'] = array(
'#title' => t('My Textarea'),
'#type' => 'textarea',
'#description' => t('Enter some text'),
'#default value' => '',
'#required' => TRUE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Add item'),
);
return $form;
}
【问题讨论】:
-
感谢您的回答,但使用不带括号的 drupal_get_form 它仍然给我一个 404 错误
-
评论太长了,所以我把它删除并作为答案。