我是Drupal的新手。我用以下代码创建了一个contace1模块:
; $Id$
name = Contact1
description = Show how to build contact form
package = Pro Drupal Development
core = 6.x
// $Id$
/**
* @file
* practice to build form
*/
/**
* Implimentation of hook_menue().
*/
function contact_menu()
{
$items['contact1'] = array(
'title' => 'Contact',
'page callback' => 'contact_page',
'access argument' => array('access content'),
'type'=>MENU_CALL_BACK,
'access callback' => TRUE,
);
return $items;
}
/**
* menu callback
* called when user goes to http://localhost/drupaldemo/?q=contact
*/
function contact_page()
{
$output = t('You can leave a message using the contact form below.');
//Return the html generated from $form data structure.
$output.= drupal_get_form('contact_nameform');
return $output;
}
/**
* define the form
*/
function contact_nameform()
{
$form['user_name']= array(
'#title' =>t('Your Name'),
'#type' => 'textfield',
'#description' => t('Please enter your name.'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
) ;
return $form;
}
/**
* validate the form
**/
function contact_nameform_validate()
{
if($form_state['values']['user_name']=="")
{
form_set_error('user_name',t('Please enter your name.'));
}
}
/**
* handle post validation form submition
*/
function contact_nameform_submit($form ,&$form_state)
{
$name=$form_state['values']['user_name'];
drupal_set_message(t('Thanks for filling out the form, %name',array('%name'=>$name)));
}
我这个代码我试图创建新的联系表格
但它没有显示任何链接,并且在打开页面上直接找不到页面。
答案 0 :(得分:3)
首先,Drupal中没有定义MENU_CALL_BACK
。你想写的是MENU_CALLBACK
,它在菜单路由器中注册一个菜单项。此项目通常不会出现在任何可见菜单中。可以将其视为隐藏的菜单项。如果您想让它可见,请使用MENU_NORMAL_ITEM
。
答案 1 :(得分:1)
'type'= MENU_CALL_BACK - 菜单是回调,您应该将其设置为MENU_NORMAL_ITEM或手动创建管理页面中的菜单以联系1页面。刷新缓存。
我建议你完全阅读Vandyk的“Pro Drupal Development”,有关如何创建表格的例子:)
答案 2 :(得分:0)
代码中的第一个错误是,如果模块名为contact1.module,那么它实现的每个钩子都应该有一个以contact1_开头的名称。然后,您应该避免在模块的函数名称中使用contact_,因为Drupal 6中已经有了Contact模块;如果您的模块用于Drupal 6,则模块之间会发生冲突。
第二个错误是你使用的常量是MENU_CALLBACK
,而不是MENU_CALL_BACK
。
如果那时contact1.module是模块的名称,则随附的info文件应命名为contact1.info,而不是contace1.info。如果您对该文件使用了错误的名称,Drupal 6及更高版本不应该在您可以安装的模块列表中显示您的模块。
答案 3 :(得分:0)
您好试着使用此代码
comboBox
在这里,我设置标记类型以返回包含内容和表单的输出,同时设置 contact_nameform($ form,$ form_state)
的参数