【问题标题】:How to create form in Drupal 7如何在 Drupal 7 中创建表单
【发布时间】:2015-04-01 10:20:59
【问题描述】:

我想在 Drupal 7 中创建一个类似于以下链接的表单:https://bmicalculator.cc/?gclid=CIrvnaXv1MQCFQwnjgodvWgAlQ

表格应以文本“BMI Calculator”开头,然后是链接中类似的 2 列,然后注意类似于“BMI 对人们来说可能不准确...”的文本

我知道一点 Drupal Form Api,所以我可以创建表单,但是如何在顶部显示文本,如何在 2 列中创建表单,然后在表单之后再次创建文本。

我是 Drupal 的新手,因此对 drupal 的工作原理没有深入的了解。

【问题讨论】:

    标签: php drupal-7 drupal-modules drupal-theming


    【解决方案1】:

    要在顶部显示文本,请使用表单渲染数组中的#markup 项。然后,您可以在此标记中嵌入您需要的 html。

    对于这两列,在表单渲染数组中使用#container 类型。这允许您将<div> 包裹在子元素周围。然后,您可以根据需要浮动 div。

    所以一个例子是

    $form = array(
    /*
     * ... form header info here
     */
     'header' => array(
       '#markup'=>'<h1> BMI Calc </h1>',
     ),
     'col1'=>array(
       '#type'=>'container',
       'subitemA'=>array(
          //some stuff
       ),
       'subitemB'=>array(
          //some stuff
       ),
       '#attributes' => array(
         'class' => array('class-name'),  //use css to float left
         //alternatively float left using style in this area
         ),
       ),
       'col2'=>array(
         '#type'=>'container',
         'subitemA'=>array(
            //some stuff
         ),
         'subitemB'=>array(
            //some stuff
         ),
         '#attributes' => array(
           'class' => array('class-name'),  //use css to float left
           //alternatively float left using style in this area
           //NOTE: still float left, the divs will align as two columns unless
           //screen space is too small, then it will stack responsively.
         ),
       ),
    );
    

    希望这会有所帮助。

    【讨论】:

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