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条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度