我想从特定的 Drupal 网络表单中删除提交按钮,这可能吗?如果可以,我该怎么做?
如果可能的话,我还想从同一个表单中删除上一个按钮。
如@googletop 所示,您需要使用 hook_form_alter() 来定位和更改该表单
要取消提交,可以在自定义模块中执行以下操作:
<?php
function my_custom_module_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'webform_client_form_130') {
if ($thiscondition && $thatcondition){
unset($form['actions']['submit']);
}
}
}
?>
与“上一个”按钮相同,您只需要在表单数组中找到它
webform-form.tpl.php
webform-form-{nid}.tpl.php
nid 等于您的节点 IDprint drupal_render($form['submitted']);
,
unset($form['actions']['submit']);
这个对我有用。
您可以更改 drupal 中的任何形式,使用hook_form_alter
.
如果您想快速修复原型等,那么您可以在 CSS 中隐藏按钮。
.block-webform .form-actions {
visibility:hidden;
}
隐形按钮仍会占用空间,但您将无法看到它。
我在 中使用了这些简单的 php 行,webform-form.tpl.php
因为创建 awebform-form-{nid}.tpl.php
或 a webform-form-[nid].tpl.php
(在模板文件中指定)不起作用。所以我只是在 webform 上使用了 if 条件$nid
来取消设置特定 webform 节点上的提交按钮。
print drupal_render($form['submitted']);
$arrayWithoutSubmitButton = array( 29, 30, 31, 32);
if( in_array( $nid, $arrayWithoutSubmitButton)){
unset($form['actions']['submit']);
}
感谢这一点,对我来说,Etno 的解决方案有效:其他解决方案由于某种原因不起作用。
我唯一要补充的是,提到的文件在“/sites/all/modules/webform/templates/webform-form.tpl.php”中,而不是“/drupal/sites/all/modules/中的文件” webform/templates/webform-form.tpl.php”(如果你有这样的文件)——我花了一段时间才弄清楚:)