Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在drupal模块内创建表单?_Php_Drupal_Drupal 7_Drupal Modules_Drupal Fapi - Fatal编程技术网

Php 如何在drupal模块内创建表单?

Php 如何在drupal模块内创建表单?,php,drupal,drupal-7,drupal-modules,drupal-fapi,Php,Drupal,Drupal 7,Drupal Modules,Drupal Fapi,我在网上搜索一个教程,创建一个显示在页面上的表单, 当我们使用模块和块显示内容时,是否在模块内显示表单? 因为我是drupal新手,所以我对drupal的形式没有概念。 我下载并安装了示例表单模块。但我不知道这张表格会显示在哪里。 我从这里下载的 即使您是drupal新手,也没有那么复杂。在这个示例中,我所要做的就是使用()并了解来自的可用表单项 下面是一个你想做的例子 /** * Implementation of hook_menu() */ function mymodule_menu

我在网上搜索一个教程,创建一个显示在页面上的表单, 当我们使用模块和块显示内容时,是否在模块内显示表单? 因为我是drupal新手,所以我对drupal的形式没有概念。 我下载并安装了示例表单模块。但我不知道这张表格会显示在哪里。 我从这里下载的

即使您是drupal新手,也没有那么复杂。在这个示例中,我所要做的就是使用()并了解来自的可用表单项

下面是一个你想做的例子

/**
 * Implementation of hook_menu()
 */
function mymodule_menu()
{
    $items = array();

    $items['my-custom-page-path'] = array(
        'title'             => 'My Page Title',
        'description'       => t(''),
        'access callback'   => 'user_access',
        'access arguments'  => array('access content'),
        'page callback'     => 'drupal_get_form',
        'page arguments'    => array('mymodule_form_id'),
    );

    return $items;
}

function mymodule_form_id($form, &$form_state)
{
    $form = array();

    $form['my_textfield'] = array(
        '#type'         => 'textfield',
        '#title'        => t('Text Field'),
        '#description'  => t(''),
        '#weight'       => 20,
        '#required'     => TRUE,
        '#size'         => 5,
        '#maxlength'    => 5,
    );

    $form['submit'] = array(
        '#type'         => 'submit',
        '#value'        => t('Save settings'),
        '#weight'       => 10000,
    );

    return $form;
}

/**
* Form validation callback
*/
function mymodule_form_id_validate($form, &$form_state)
{
    // notice adding "_validate" to the form id
}

/**
* Form submission callback
*/
function mymodule_form_id_submit($form, &$form_state)
{
    // notice adding "_submit" to the form id
}
#Here is the simple code for creating form in module#

===============================================================

/*..firstly create a menu in module by copying this code..*/
function form_test_menu() {
    $items['formtest'] = array(
                        'title' => 'Form Test',
                        'page callback' => 'drupal_get_form',
                        'page arguments' => array('form_test_form'),
                        'access callback' => TRUE,
                        );
    return $items;
}

/*...Now create fields like below...*/
function form_test_form($form,&$form_submit) {
    $form['firstname'] = array(
                            '#title' => t('Firstname'),
                            '#type' => 'textfield',
                            '#required' => TRUE,
                            );
    $form['lastname'] = array(
                            '#title' => t('Lastname'),
                            '#type' => 'textfield',
                            );
    $form['submit'] = array(
                        '#value' => 'Submit',
                        '#type' => 'submit',
                        );
    return $form;
}