簡體   English   中英

Drupal Form模塊開發

[英]Drupal Form module development

我正在drupal 7中通過名稱“ form”開發自定義模塊。我已將模塊文件夾放置在sites \\ all \\ modules \\ form中。 我在“ form”文件夾中有2個文件。 “ form.info”和“ form.module”。

'form.info'

name = Form
description = Form creation.
core = 7.x

並且“ form.module”包含

<?php
function form_menu()
{
$items['form/examples'] = array
(
    'title' => 'Form API Examples',
    'description' => 'Examples of using the Form API',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('form_simple_form'),
    'access callback' => TRUE
);
return $items;
}

function form_simple_form($form, &$form_submit)
{
$form['color'] = array
(
    '#title' => t('Favorite Color'),
    '#type' => 'textfield',
    '#required' => TRUE,
    '#description' => t('What is the favorite color?'),
);
$form['submit'] = array
(
    '#type' => 'submit',
    '#value' => 'Submit',
)
return $form;

}

當我單擊鏈接時,我只會得到空白的白頁。

提前致謝。

將您的模塊重命名為form1,因為它與位於/ includes中的Drupal內部表單模塊沖突。

您在這里忘記了分號:

$form['submit'] = array
(
    '#type' => 'submit',
    '#value' => 'Submit',
); //<- semicolon missing

我為我工作嘗試為mymodule.module將此代碼

 <?php
 // $Id$
    function form_menu()
    {
    $items['form/examples'] = array
    (
        'title' => 'Form API Examples',
        'description' => 'Examples of using the Form API',
        'page callback' => 'drupal_get_form',
        'page arguments' => array('form_simple_form'),
        'access callback' => TRUE
    );
    return $items;
    }

    function form_simple_form($form, &$form_submit)
    {
    $form['color'] = array
    (
        '#title' => t('Favorite Color'),
        '#type' => 'textfield',
        '#required' => TRUE,
        '#description' => t('What is the favorite color?'),
    );
    $form['submit'] = array
    (
        '#type' => 'submit',
        '#value' => 'Submit',
    );
    return $form;
    }

創建mymodule.info文件時

  name = Form
  description = Form creation.
  core = 7.x
  package = Form

向其中添加軟件包,這樣您就可以在自己的盒子中放置模塊了。 在所有這些模塊之間更容易找到它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM