drupal-7 - Drupal 7:自定义模块模板中的自定义表单
问题描述
我正在为 Drupal 7 站点创建一个自定义模块,我需要使用表单挂钩创建一个表单,然后将其包含在自定义模块的模板中。
我在 .module 文件中创建了一个简单的表单:
function my_login_form($form, &$form_state) {
$form['email_address'] = array(
'#type' => 'textfield',
'#attributes' => array('placeholder' => t('Email Address')),
);
$form['phone'] = array(
'#type' => 'password',
'#attributes' => array('placeholder' => t('Password')),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Login',
);
return $form;
}
在我的 hook_menu() 中,我创建了一条路线,并且“页面回调”指向了该函数:
function my_login(){
return theme('my_login_template');
}
在我的 hook_theme() 函数中,我将它指向 .tpl:
function my_theme(){
return array(
'my_login_template' => array(
'template' => 'login',
),
);
}
如何将 my_login_form 放入 login.tpl.php 文件?
感谢您提供的任何帮助或您可以指出的任何地方。
解决方案
您需要将其传递给主题:
function my_login(){
$form = drupal_get_form('my_login_form');
return theme('my_login_template', array('form' => render($form)));
}
进入你的 tpl :
<?php print $form; ?>
清除缓存主题
推荐阅读
- javascript - 内部 $.getJSON 不会转到循环中的第二个元素
- matlab - 将复合函数与 Matlab 集成的问题
- java - 在询问用户是否要继续后,如何一次打印出一个 HashMap KeyValue?
- amazon-web-services - AWS - 我可以在 DNS 域(Auto Scale Group)下启动节点吗?
- ios - Xcode 11 向后兼容性:“UIWindowScene 仅在 iOS 13 或更高版本中可用”
- ruby-on-rails - 将 rails 应用程序部署到 Heroku 错误 ArgumentError:无效选项:和谐
- node.js - 如何从 node.js 中的连续图像流创建 MediaStream 轨道?(用于 WebRTC)
- python - __init__() 接受 1 个位置参数,但给出了 3 个
- karate - 如何在空手道中测试数组的顺序
- ios - 我试图重新创建从一个屏幕到另一个屏幕的表格视图,但不断收到错误信号 sigbart