我是新来的Drupal。我已经创建了一个contace1模块用以下代码:

contace1.info

; $Id$
name = Contact1
description = Show how to build contact form
package = Pro Drupal Development
core = 6.x

contact1.module

// $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)));

    }

即时消息验证码我试图创建新的联系人形式

,但它不表现出任何链路和上开口页直接给出页面未找到。

没有正确的解决方案

其他提示

首先,MENU_CALL_BACK不会在Drupal定义。你想写是MENU_CALLBACK,这在菜单路由器注册了一个菜单项。这个项目不会出现在任何可见的菜单正常。把它看成是一个隐藏的菜单项。如果你想使其可见,使用MENU_NORMAL_ITEM

“类型” = MENU_CALL_BACK - 菜单回调,你应该把它设置为MENU_NORMAL_ITEM或手动创建管理页面菜单contact1页。刷新缓存。 搜索结果我建议你充分阅读Vandyk“临Drupal的发展”,有例子,说明如何创建表单:)

在代码中的第一个错误是,如果该模块被命名为contact1.module,然后每钩它实现应该有一个名称以contact1_。那么你应该避免在你的模块的功能名称使用contact_,因为已经有在Drupal 6中的联系人模块;在您的模块是为Drupal 6的情况下,将有在模块之间的冲突。

第二个错误是所使用的常数是MENU_CALLBACK,不MENU_CALL_BACK

如果再contact1.module是你的模块,自带的,应当命名为contact1.info,不contace1.info的信息文件的名称。如果该文件使用了错误的名称,Drupal的6和更高的不应该显示你的模块可以安装的模块列表。

您好尝试使用此代码

/**
* menu callback
*
*/

function contact_page()
    {
        $output = array(
            'item 1' => array(
              "#type" => 'markup',
              '#markup' =>  t('You can leave a message using the contact form below.'),
            ),
            'item 2' => array(
              "#type" => 'markup',
              '#markup' =>  drupal_get_form('contact_nameform'),
            ),
        );
        return $output;
    }
    /**
    * define the form
    */
function contact_nameform($form, $form_state)
    {  ..........
       .......

下面,我将标记类型与内容和形式返回输出,也将 contact_nameform($形式,$ form_state)

的参数
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top