【问题标题】:Drupal 7 form not showing on pageDrupal 7 表单未显示在页面上
【发布时间】:2016-07-12 07:58:22
【问题描述】:

我是 Drupal 的新手。我创建了一个简单的页面,并通过使用页面节点 ID 创建了一个页面。我想在该页面中添加表单,但无法这样做,但是当我添加任何简单的文本时,它可以工作,但表单元素不行。我不知道如何使用表单 API 添加表单。

<?php simple text which is showing on page ."; 
 $form['submit_button'] = array(
'#type' => 'submit',
'#value' => t('Click Here!'),
);

【问题讨论】:

    标签: php drupal-7 drupal-theming


    【解决方案1】:

    这应该有助于为您指明正确的方向。 Drupal 7 - How to Make a Simple Module with a Form and Menu Link

    【讨论】:

      【解决方案2】:

      可以通过模块来完成我有一个.module文件

      function module_name_menu() {
        $items = array();
        $items['module_name/form'] = array(
          'title' => t('My form'),
          'page callback' => 'drupal_get_form',
          'page arguments' => array('my_module_my_form'),
          'access arguments' => array('access content'),
          'description' => t('My form'),
          'type' => MENU_CALLBACK,
        );
        return $items;
      }
      function my_module_my_form($form, &$form_state) {
        $form['name']= array(
          '#type' => 'textfield',
          '#title' => t('Name'),
          '#required' => TRUE,
          '#description' => "Please enter your name.",
          '#size' => 20,
          '#maxlength' => 20,
        );
         $form['mail'] = array(
          '#type' => 'textfield',
          '#title' => t('Email'),
          '#required' => TRUE,
          '#description' => "Please enter your Email.",
          '#size' => 30,
          '#maxlength' => 30,
        );
         $form['phno'] = array(
          '#type' => 'textfield',
          '#title' => t('Phone No'),
          '#required' => TRUE,
          '#description' => "Please enter your Contact Number.",
          '#size' => 30,
          '#maxlength' => 30,
        );  
        $form['submit'] = array(
          '#type' => 'submit',
          '#value' => 'Submit',
        );
        return $form;
      }
      

      然后通过 druple_get_form 在您想要的任何页面上呈现此表单,这可以通过

      <?php
                  $form = drupal_get_form('my_module_my_form');
                  print drupal_render($form);
      
              ?>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-09-21
        • 1970-01-01
        相关资源
        最近更新 更多