如何从Drupal 8的联系表中的输入中删除默认值

时间:2019-02-08 11:06:46

标签: drupal-8 drupal-webform

我正在使用Drupal8,我必须创建一个Web表单。问题是,我的名字和地址邮件会自动输入到条目中。我不希望这样。我正在搜索设置,但找不到我的名字,等等...

如何删除它们?

 My webform :

    Full Name:
       Cecile

    Mail:
       cecile@jfdifjid.Fr

你知道我的意思吗?我想删除它并添加占位符。

先谢谢您

塞西尔

2 个答案:

答案 0 :(得分:0)

请在您的module.theme(模块是您的主题名称)文件中使用带有表单ID的hook form_alter。 请参阅此enter link description here

答案 1 :(得分:0)

我不知道该钩子如何处理:

   <?php

/**
 * @file
 * Support module for webform that tests form and element alter hooks.
 */

use Drupal\Core\Form\FormStateInterface;

/******************************************************************************/
// Form hooks.
/******************************************************************************/

/**
 * Implements hook_form_alter().
 */
function webform_test_alter_hooks_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  if (strpos($form_id, 'webform_') === 0) {
    \Drupal::messenger()->addStatus(t("@hook: '@form_id' executed.", ['@hook' => 'hook_form_alter()', '@form_id' => $form_id]), TRUE);
  }
}

/**
 * Implements hook_form_webform_submission_form_alter().
 */
function webform_test_alter_hooks_form_webform_submission_form_alter(array $form, FormStateInterface $form_state, $form_id) {
  \Drupal::messenger()->addStatus(t("@hook: '@form_id' executed.", ['@hook' => 'hook_form_webform_submission_form_alter()', '@form_id' => $form_id]), TRUE);
}

/**
 * Implements hook_form_webform_submission_BASE_FORM_ID_form_alter().
 *
 * @see webform_form_alter()
 * @see \Drupal\webform\WebformSubmissionForm::getBaseFormId
 * @see \Drupal\Core\Form\FormBuilder::prepareForm
 */
function webform_test_alter_hooks_form_webform_submission_contact_form_alter(array $form, FormStateInterface $form_state, $form_id) {
  \Drupal::messenger()->addStatus(t("@hook: '@form_id' executed.", ['@hook' => 'hook_form_webform_submission_BASE_FORM_ID_form_alter()', '@form_id' => $form_id]), TRUE);
}

/**
 * Implements hook_form_webform_submission_FORM_ID_form_alter().
 *
 * @see webform_form_alter()
 * @see \Drupal\webform\WebformSubmissionForm::getFormId
 * @see \Drupal\Core\Form\FormBuilder::prepareForm
 */
function webform_test_alter_hooks_form_webform_submission_contact_add_form_alter(array $form, FormStateInterface $form_state, $form_id) {
  \Drupal::messenger()->addStatus(t("@hook: '@form_id' executed.", ['@hook' => 'hook_form_webform_submission_FORM_ID_form_alter()', '@form_id' => $form_id]), TRUE);
}

/**
 * Implements hook_form_webform_submission_FORM_ID_form_alter().
 *
 * @see webform_form_alter()
 * @see \Drupal\webform\WebformSubmissionForm::getFormId
 * @see \Drupal\Core\Form\FormBuilder::prepareForm
 */
function webform_test_alter_hooks_form_webform_submission_contact_node_1_add_form_alter(array $form, FormStateInterface $form_state, $form_id) {
  \Drupal::messenger()->addStatus(t("@hook: '@form_id' executed.", ['@hook' => 'hook_form_webform_submission_FORM_ID_form_alter()', '@form_id' => $form_id]), TRUE);
}

/**
 * Implements hook_webform_submission_form_alter().
 *
 * @see \Drupal\webform\WebformSubmissionForm::buildForm
 */
function webform_test_alter_hooks_webform_submission_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
  \Drupal::messenger()->addStatus(t("@hook: '@form_id' executed.", ['@hook' => 'hook_webform_submission_form_alter()', '@form_id' => $form_id]), TRUE);
}

/******************************************************************************/
// Element hooks.
/******************************************************************************/

/**
 * Implements hook_webform_element_alter().
 *
 * @see webform.api.php
 * @see \Drupal\webform\WebformSubmissionForm::prepareElements
 */
function webform_test_alter_hooks_webform_element_alter(array &$element, FormStateInterface $form_state, array $context) {
  \Drupal::messenger()->addStatus(t("@hook: '@webform_key' executed.", ['@hook' => 'hook_webform_element_alter()', '@webform_key' => $element['#webform_key']]), TRUE);

}

/**
 * Implements hook_webform_element_ELEMENT_TYPE_alter().
 *
 * @see webform.api.php
 * @see \Drupal\webform\WebformSubmissionForm::prepareElements
 */
function webform_test_alter_hooks_webform_element_email_alter(array &$element, FormStateInterface $form_state, array $context) {
  \Drupal::messenger()->addStatus(t("@hook: '@webform_key' executed.", ['@hook' => 'hook_webform_element_ELEMENT_TYPE_alter()', '@webform_key' => $element['#webform_key']]), TRUE);
}