[英]simple example form in drupal 7 with everything configured correctly shows “Page not found”..Why..?
我已經安裝了 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://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 中之后,我從模塊頁面啟用了模塊,沒有任何錯誤或警告。
現在,當我嘗試使用 url 訪問它時, localhost/d7/?q=my_module/form
我收到“找不到頁面”錯誤..!! 為什么..?? 我錯過了什么..?
它不僅適用於此模塊,還適用於開發人員模塊http://drupal.org/project/examples 的此示例。 它顯示相同的錯誤。
你應該寫:
$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
我希望這對你有用
我知道這已經晚了,但我確實相信您需要將 $form 變量傳遞到您的表單中,如下所示:
函數 my_module_my_form($form_state, $form)...
這樣,您實際上就有了一個表單變量來存放表單數據。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.