Drupal - Webform 元素主题
关于 Drupal webforms 的另一个问题—— 内置
表单本身由 /includes/form.inc 的 function theme_form_element($element, $value)
,并添加一个 元素添加到 $output。我只想删除一个网络表单的标签,所以我必须重写该函数。 如何仅针对一个网络表单覆盖它,同时在所有其他网络表单中保持相同? 例如,
if ($block == 'contact'):
// only output <input> form element stored in $value
function mytheme_html_form_element($element, $value) {
$t = get_t();
$output .= " $value\n";
return $output;
}
endif;
这可能吗?if 条件会发生什么?
Another question about Drupal webforms --
The form itself is built in by /includes/form.inc's
function theme_form_element($element, $value)
and adds a <label>
element to the $output. I want to remove that label only for one webform, so I have to override the function.
How can I override it for only one webform, while leaving it the same in all others?
E.g.
if ($block == 'contact'):
// only output <input> form element stored in $value
function mytheme_html_form_element($element, $value) {
$t = get_t();
$output .= " $value\n";
return $output;
}
endif;
Is this possible, and what goes in the if condition?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您只是想删除标签,也可以使用 hook_form_alter(),并检查 $form_id 是否等于相关的网络表单。 id 的格式为:webform_client_form_N,其中 N 是 Webform 的节点 ID。
一旦您在正确的表单上进行操作,您就可以使用以下代码取消设置标签:
这将取消名为first_name 的字段的标签设置。
If you're just looking to remove the label, you can also use hook_form_alter(), and check that $form_id is equal to the webform in question. The id will be of the form: webform_client_form_N where N is the node ID of the webform.
Once you're operating on the proper form, you can unset the label using, for example, code like this:
Which would unset the label for a field called first_name.
我确实必须执行 hook_form_alter,但标签本身位于 ['subscribed'] 元素中。
这是不同形式的代码
,删除了 #title 有效(为你+1!),但这是一个不同的情况。
i did have to do a hook_form_alter, but the label itself was in the ['submitted'] element.
here is the code
in a different form, removing the #title worked (+1 for you!), but this was a different case.
我不会取消设置表单元素标题。当主题引擎呈现您的表单时,您可能会得到意想不到的结果。
您可以通过多种方式完成此操作:
使用 with
'#theme' => 为每个元素或整个表单设置主题'my_callback'
。您还可以使用 hook_elements 创建自己的表单元素,该元素使用相应的主题挂钩。
请参阅:
http://api.drupal.org/api/ drupal/developer--topics--forms_api_reference.html
http://api .drupal.org/api/function/hook_elements/6
I wouldn't unset form element titles. You could get unexpected results when your form gets rendered by the theme engine.
You can do it several ways:
Theme each element or the whole form with with
'#theme' => 'my_callback'
.You can also create your own form element using hook_elements that uses a corresponding theme hook.
See:
http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.html
http://api.drupal.org/api/function/hook_elements/6