自定义模块表单问题
我正在努力尝试以编程方式显示要在节点页面视图区域中显示的表单。我的“简单模块”中有以下代码。
function simplemodule_newcomer_form($form_state){
$form = array();
$form['simplemodule_newcomer']['name'] = array(
'#type' => 'textfield',
'#title' => t('name'),
'#description' => t(''),
'#weight' => -1,
);
$form['simplemodule_newcomer']['email'] = array(
'#title' => t('email'),
'#type' => 'textfield',
'#description' => t(''),
'#weight' => 0,
);
$form['simplemodule_newcomer']['phone'] = array(
'#title' => t('telephone No.'),
'#type' => 'textfield',
'#description' => t(''),
'#weight' => 0,
);
$form['submit_button'] = array(
'#type' => 'submit',
'#value' => 'enter',
);
return $form;
}
function simplemodule_newcomer_form_submit($form_id, &$form_state){
//dealing with submitted data
}
该代码可以工作,但只能通过我的管理菜单中定义的链接进行。
我想要做的是让表单在视图模式下在特定节点上显示并提交。这样就造成了访问节点时有一个表单需要填写的效果。
I am struggling in my attempts to programmatically display a form to display in my node-page view area. I have the following code in my "simplemodule".
function simplemodule_newcomer_form($form_state){
$form = array();
$form['simplemodule_newcomer']['name'] = array(
'#type' => 'textfield',
'#title' => t('name'),
'#description' => t(''),
'#weight' => -1,
);
$form['simplemodule_newcomer']['email'] = array(
'#title' => t('email'),
'#type' => 'textfield',
'#description' => t(''),
'#weight' => 0,
);
$form['simplemodule_newcomer']['phone'] = array(
'#title' => t('telephone No.'),
'#type' => 'textfield',
'#description' => t(''),
'#weight' => 0,
);
$form['submit_button'] = array(
'#type' => 'submit',
'#value' => 'enter',
);
return $form;
}
function simplemodule_newcomer_form_submit($form_id, &$form_state){
//dealing with submitted data
}
This code works but only from a defined link in my administration menu.
What I want to do is get the form to display and submit on a specific node in view mode. So it creates the effect that there is a form to fill when visiting the node.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当然你可以使用
http:// /api.drupal.org/api/drupal/modules--system--system.api.php/function/hook_form_alter/7
http://drupal.org/node/1011692
Surely you can use
http://api.drupal.org/api/drupal/modules--system--system.api.php/function/hook_form_alter/7
http://drupal.org/node/1011692
您可以实现
hook_nodeapi()
并使用drupal_get_form()
:您可以使用
#weight
键来指定表单相对于页面上其他内容的位置出现。此外,当您实现此挂钩时,您还需要清除 Drupal 的缓存以确保它被选中。You can implement
hook_nodeapi()
and attach your form usingdrupal_get_form()
:You can use the
#weight
key to specify where in relation to the other content on the page your form will appear. Also you'll need to clear Drupal's caches when you implement this hook to make sure it's picked up.