doupao3662 2014-02-05 09:35
浏览 44
已采纳

Drupal Form模块开发

I am developing a custom module by name 'form' in drupal 7. I have placed my module folder in sites\all\modules\form. And i have 2 files in 'form' folder. 'form.info' and 'form.module'.

'form.info'

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

And 'form.module' contains

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

}

I am getting only blank white page when i click on the link.

Thanks in advance.

  • 写回答

2条回答 默认 最新

  • duan00529 2014-02-06 09:26
    关注

    I works for me try this code for 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;
        }
    

    When you create mymodule.info file

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

    Add package to it so you have your module in his own box. It is easier to find it betwen all of those modules.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图2.0 版本点聚合中Marker的位置无法实时更新,如何解决呢?
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题