如何主题自定义表单(drupal 6.x)
DRUPAL 6.X
我的自定义模块中有这个自定义表单构造函数,它是通过 ajax 请求调用的。我正在尝试使用驻留在我的主题目录中的模板文件来主题化此表单。就此而言,我已在 template.php 文件中注册了我的主题,该文件位于我的主题文件夹中。该文件如下所示 –
function my_theme() {
return array(
'searchdb' => array(
'arguments' => array('form' => NULL),
'template' => 'searchform',
)
);
}
以下是模块代码的摘录 –
function test_menu() {
$my_form['searchdb'] = array(
'title' => 'Search db',
'page callback' => 'get_form',
'page arguments' => array(0),
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $my_form;
}
function get_form($formtype){
switch($formtype){
case 'searchdb' :
echo drupal_get_form('searchdb');
break;
}
}
function searchdb(){
$form['customer_name'] = array(
'#type' => 'textfield',
'#title' => t('Customer Name'),
'#size' => 50,
'#attributes' => array('class' => 'name-textbox'),
);
return $form;
}
正如您可以想象的那样,这根本不起作用。只是为了测试我的主题是否已注册,我还使用主题函数进行了测试,但是它没有被调用。我已经检查了模板文件名和表单 ID(通过输出的 html 源),一切似乎都正常。如果有人能指出我正确的方向,我会很高兴。
DRUPAL 6.X
I have this custom form constructor inside my custom module which is invoke through ajax request. I’m attempting to theme this form with the template file reside in my theme directory. For that matter, I’ve registered my theme inside template.php file which reside in my theme folder. Here’s how this file looks –
function my_theme() {
return array(
'searchdb' => array(
'arguments' => array('form' => NULL),
'template' => 'searchform',
)
);
}
And the following is the excerpt of module code –
function test_menu() {
$my_form['searchdb'] = array(
'title' => 'Search db',
'page callback' => 'get_form',
'page arguments' => array(0),
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $my_form;
}
function get_form($formtype){
switch($formtype){
case 'searchdb' :
echo drupal_get_form('searchdb');
break;
}
}
function searchdb(){
$form['customer_name'] = array(
'#type' => 'textfield',
'#title' => t('Customer Name'),
'#size' => 50,
'#attributes' => array('class' => 'name-textbox'),
);
return $form;
}
As you can imagine, this is not working at all. Just to test if my theme is even registered, I’ve also tested with theme function but, it’s not called. I've checked template file name and form-id(through the outputted html source) and everything seems ok. I would be glad if anyone could point me to the right direction.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的表格也遇到了同样的问题。它与 PHP 版本和主题过程中调用的 php 函数有关,该函数用于从主题函数获取输出:call_user_func_array。
在 php 5.2 及更低版本中,它接受 Drupal 传入的结构化 $form 数组。但是,在 php 5.3 中它消失了。
我通过将 php 版本回滚到 5.2.14 解决了我的问题。
该解决方案适用于 Drupal 6。我尚未在 Drupal 7 中测试它,因为 D7 声称与 php 5.3 兼容。
I ran into the same issue with my forms. It has to do with the PHP version and the php function that is called in the theming process to get output from your theme function: call_user_func_array.
In php 5.2 and below it accepts the structured $form arrays that Drupal passes in. However, in php 5.3 it dies.
I solved my issue by rolling back my php version to 5.2.14.
This solution applies to Drupal 6. I haven't tested it in Drupal 7 as D7 claims to be php 5.3 compatible.