use*_*765 3 php drupal drupal-7 drupal-fapi drupal-forms
我需要在Drupal 7中向节点添加一个程序化表单.如何将表单附加到节点?
function addtabexample_form($node, &$form_state) {
$type = node_type_get_type($node);
$form['title'] = array(
'#type' => 'textfield',
'#title' => check_plain($type->title_label),
'#default_value' => !empty($node->title) ? $node->title : '',
'#required' => TRUE,
'#weight' => -5,
);
$form['field1'] = array(
'#type' => 'textfield',
'#title' => t('Custom field'),
'#default_value' => $node->field1,
'#maxlength' => 127,
);
return $form;
}
Run Code Online (Sandbox Code Playgroud)
您可以使用hook_node_view()来关注此代码示例
function [YOUR_MODULE]_node_view($node, $view_mode, $langcode)
{
$my_form = drupal_get_form('addtabexample_form', $node);
$node->content['my_form_attached'] = array(
'#markup' => drupal_render($my_form),
'#weight' => 10,
);
}
Run Code Online (Sandbox Code Playgroud)
希望这有效......穆罕默德.
| 归档时间: |
|
| 查看次数: |
6591 次 |
| 最近记录: |