3

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;
}

?>

これら 2 つのファイルを *my_module* フォルダーに配置し、sites/all/modulesに配置しました 。その後、エラーや警告なしでモジュール ページからモジュールを有効にしました。

ここで、URL を使用してこれにアクセスしようとすると、localhost/d7/?q=my_module/form

「ページが見つかりません」というエラーが表示されます..!! どうして..??私は何が欠けています..?

このモジュールだけでなく、この例の開発者モジュールhttp://drupal.org/project/examplesも対象です。同じエラーが表示されます。

4

2 に答える 2

0

私はこれが遅いことを知っていますが、次のように $form 変数をフォームに渡す必要があると信じています: function my_module_my_form
($form_state, $form)...
フォームデータ。

于 2013-10-17T16:47:08.713 に答える
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

これがあなたに役立つことを願っています

于 2012-10-09T05:10:31.333 に答える