We will utilize the core hook_form_alter
hook to alter the core contact form to display placeholders for name and e-mail fields. We will be adding this code to the d8dev.module
file:
In PhpStorm, open the
d8dev.module
file in your custom module at/modules
.Next, switch over to the browser with the core contact form loaded, and find the
form_id
of the form element. Right-click on the page and click on View source code. On the next page, you can see HTML code. Now search forform_id
and you will find thatcontact_message_feedback_form is
the required form ID.In another way, we can use the
drupal_set_message()
core function to find theform_id
. To do this, we need to add the following code on top of thed8dev.module
file:use Drupal\Core\Form\FormStateInterface; /** * Implements hook_form_alter(). */ function d8dev_form_alter(&$form, FormStateInterface $form_state, $form_id) { drupal_set_message($form_id); }
Now, reload...