如何从联系人表单中删除预览按钮?


Answers:


14

定制模块可hook_form_alter()用于以任何形式剥离预览按钮表单元素:

/**
 * Implements hook_form_alter().
 */
function MYMODULE_form_alter(&$form, $form_state, $form_id) {

  // Look for any form provided by the contact module.
  // If you want to target a specific form you'll use the whole form ID
  // (e.g. Website feedback = 'contact_message_feedback_form').
  if (strpos($form_id, 'contact_message_') !== FALSE) {
    $form['actions']['preview']['#access'] = FALSE;
  }
}

1
如果我还记得,删除表单元素而不使用unset()的首选方法是将#access属性设置为FALSE,因此:$ form ['actions'] ['preview'] ['#access'] = FALSE ;
batigolix

它不适用于D8中的操作按钮。如果此问题已解决或有其他选择(我没有时间研究正在发生的事情),请随时更新答案。
肖恩·康

似乎工作正常。我更新了片段
batigolix,2016年

而是通过主题实现了,hook_form_form_id_alter()钩了完整的代码段(适用于默认的联系表):function THEME_form_contact_message_feedback_form_alter(&$form, &$form_state, $form_id) { $form['actions']['preview']['#access'] = FALSE; }
tulvit

1

这对我有用。最佳方法是将此代码添加到YOURPROFILENAME.profile文件中

/**
 * Implements hook_form_alter().
 */
function YOURPROFILENAME_form_alter(&$form, $form_state, $form_id) {
   if (strpos($form_id, 'contact_message_') !== FALSE) {
    $form['actions']['preview']['#access'] = FALSE;
  }
}

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.