drupal 7中的所有配置正确的简单示例表单显示“找不到页面”..为什么......?

问题描述 投票:3回答:2

我已经安装了drupal 7并且一直在尝试创建自定义表单。我正在尝试的以下代码取自http://drupal.org/node/717722,除了.info文件之外我没有做任何更改。

这是my_module.info

name = My module
description = Module for form api tutorial
core = 7.x

下面是my_module.module

<?php

/**
* This function defines the URL to the page created etc.
* See http&#58;//api.drupal.org/api/function/hook_menu/6
*/
function my_module_menu() {
  $items = array();
  $items['my_module/form'] = array(
    'title' => t('My form'),
    'page callback' => 'my_module_form',
    'access arguments' => array('access content'),
    'description' => t('My form'),
    'type' => MENU_CALLBACK,
  );
  return $items;
}

/**
* This function gets called in the browser address bar for:
* "http://yourhost/my_module/form" or
* "http://yourhost/?q=my_module/form". It will generate
* a page with this form on it.
*/
function my_module_form() {

  // This form calls the form builder function via the
  // drupal_get_form() function which takes the name of this form builder
  // function as an argument. It returns the results to display the form.
  return drupal_get_form('my_module_my_form');

}

/**
* This function is called the "form builder". It builds the form.
* Notice, it takes one argument, the $form_state
*/
function my_module_my_form($form_state) {

// This is the first form element. It's a textfield with a label, "Name"
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
  );
  return $form;
}

?>

我已将这两个文件放在* my_module *文件夹中,并将其放在sites / all / modules中。之后,我从模块页面启用了模块,没有任何错误或警告。

现在,当我尝试使用网址localhost/d7/?q=my_module/form访问它时

我收到“找不到页面”错误.. !!为什么..??我错过了什么..?

它不仅适用于此模块,还适用于开发人员模块http://drupal.org/project/examples的此示例。它显示相同的错误。

drupal drupal-7 drupal-modules drupal-forms
2个回答
0
投票

你应该写:

$items['my_module']

其中my_module是模块名称。 你需要创建page-my_module_my_form.tpl.php文件

sites/all/theme/your_theme/template/page-my_module_my_form.tpl.php

并在此文件中添加如下代码:

<?php

if (isset($form['submission_info']) || isset($form['navigation'])) {
    print drupal_render($form['navigation']);
    print drupal_render($form['submission_info']);
}

print drupal_render($form['submitted']);

?>

<?php print drupal_render_children($form); ?>

并尝试运行

本地主机/ D7 / my_module

我希望这对你有用


0
投票

我知道这已经很晚了,但我相信你需要将$ form变量传递给你的表单,如下所示: function my_module_my_form($ form_state,$ form)... 这样你实际上有一个表单变量来存放表单数据。

© www.soinside.com 2019 - 2024. All rights reserved.