Drupal 7 表单未显示在页面上
Drupal 7 form not showing on page
我是 Drupal 新手。我创建了一个简单的页面,并通过使用页面节点 ID 创建了一个页面。我想在该页面中添加表单但无法这样做,但是当我添加任何简单文本时,它可以工作但表单元素不起作用。我不知道如何使用表单 API 添加表单。
<?php simple text which is showing on page .";
$form['submit_button'] = array(
'#type' => 'submit',
'#value' => t('Click Here!'),
);
这应该有助于为您指明正确的方向。 Drupal 7 - How to Make a Simple Module with a Form and Menu Link
可以通过模块完成我有一个.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);
?>
我是 Drupal 新手。我创建了一个简单的页面,并通过使用页面节点 ID 创建了一个页面。我想在该页面中添加表单但无法这样做,但是当我添加任何简单文本时,它可以工作但表单元素不起作用。我不知道如何使用表单 API 添加表单。
<?php simple text which is showing on page .";
$form['submit_button'] = array(
'#type' => 'submit',
'#value' => t('Click Here!'),
);
这应该有助于为您指明正确的方向。 Drupal 7 - How to Make a Simple Module with a Form and Menu Link
可以通过模块完成我有一个.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);
?>