如何在 Drupal 7 中创建表单
How to create form in Drupal 7
我想在 Drupal 7 中创建一个类似于下面 link 中的表单:https://bmicalculator.cc/?gclid=CIrvnaXv1MQCFQwnjgodvWgAlQ
表单应以文本 "BMI Calculator" 开头,然后是 link 中类似的 2 列,然后注释文本类似于 "BMI can be inaccurate for people..."
我知道一点 Drupal 表单 Api 这样我就可以创建表单,但是如何在顶部显示文本,如何在 2 列中创建表单,然后在表单之后再创建文本。
我是 Drupal 的新手,因此对 drupal 的工作原理了解不深。
要在顶部显示文本,请使用表单渲染数组中的#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.
),
),
);
希望对您有所帮助。
我想在 Drupal 7 中创建一个类似于下面 link 中的表单:https://bmicalculator.cc/?gclid=CIrvnaXv1MQCFQwnjgodvWgAlQ
表单应以文本 "BMI Calculator" 开头,然后是 link 中类似的 2 列,然后注释文本类似于 "BMI can be inaccurate for people..."
我知道一点 Drupal 表单 Api 这样我就可以创建表单,但是如何在顶部显示文本,如何在 2 列中创建表单,然后在表单之后再创建文本。
我是 Drupal 的新手,因此对 drupal 的工作原理了解不深。
要在顶部显示文本,请使用表单渲染数组中的#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.
),
),
);
希望对您有所帮助。