如何从特定 Drupal Web 表单中删除提交按钮
我想从特定的 Drupal Web 表单中删除提交按钮,这可能吗?如果可以,我该怎么做?
如果可能的话,我还想从同一表单中删除上一个按钮。
I'd like to remove the submit button from a specific Drupal webform, is this possible and if so how do I do it?
I'd also like to remove the previous button if possible as well from the same form.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您需要使用 hook_form_alter() 来定位和更改该表单,如 @googletop 所示
要取消设置提交,自定义模块中的类似操作将起作用:
与“上一个”按钮相同,您只需要找到它在表单数组中
You'll need to target and alter that form with hook_form_alter() as indicated by @googletop
To unset the submit, something like this in a custom module would work:
Same for the "previous" button, you'll just need to find it in the form array
webform-form.tpl.php
webform-form-{nid}.tpl.php
其中 nid 等于您的节点 IDprint drupal_render($form['已提交']);
,添加此行:
unset($form['actions']['submit']);
它对我有用。
webform-form.tpl.php
webform-form-{nid}.tpl.php
where nid equals your node IDprint drupal_render($form['submitted']);
,add this line:
unset($form['actions']['submit']);
It works for me.
您可以使用
hook_form_alter
更改 drupal 中的任何表单。You can alter any form in drupal, using
hook_form_alter
.如果您想快速修复原型等,那么您可以在 CSS 中隐藏按钮。
隐形按钮仍会占用一个空间,但您将看不到它。
If you'd like a quick fix for a prototype, etc then you could just hide the button in CSS.
The invisible button will still take up a space, but you won't be able to see it.
我在
webform-form.tpl.php
中使用了这些简单的 php 行,因为创建了webform-form-{nid}.tpl.php
或webform- form-[nid].tpl.php
(如模板文件中指定的)不起作用。因此,我只是在
$nid
Webform 上使用 if 条件,只是为了取消设置特定 Webform 节点上的提交按钮。I used these simple php lines in the
webform-form.tpl.php
because creating awebform-form-{nid}.tpl.php
or awebform-form-[nid].tpl.php
(as specified in the template file) does NOT work.So I simply used an if condition on
$nid
webform just to unset the submit button on specific webform nodes.感谢这一点,对我来说,Etno 的解决方案有效:其他解决方案由于某种原因不起作用。
我唯一要补充的是,提到的文件位于“/sites/all/modules/webform/templates/webform-form.tpl.php”中,而不是“/drupal/sites/all/modules/”中的文件webform/templates/webform-form.tpl.php”(如果你有这样的文件)-我花了一段时间才弄清楚:)
Thanks for this and for me, Etno's solution worked: the others didn't work for some reason.
The only thing I would add to this is that the file mentioned is in "/sites/all/modules/webform/templates/webform-form.tpl.php" and NOT the file in "/drupal/sites/all/modules/webform/templates/webform-form.tpl.php" (if you have such a file) - it took me a while to figure that out :)