I am trying to design contact form template in drupal 8. I successfully added form-contact-message-contact-form.html.twig template file. Here i can add simple classes in my form. But i not getting how to add prefix/suffix, classes in my form field for designing my form.
Any suggestions ??

Comments

neha.gangwar’s picture

But i think there will be some good solution instead of form alter. Now i need to design Email template for contact form. In my contact form i have not used default fields. I have added new fields as per my requirement. Implemented hook_mail_alter to alter email template but not getting how to print additional form elements. In drupal 7 we did something like this - $message['params']['field_name_here']. So how can we achieve the same in D8.

neha.gangwar’s picture

Yes i got the solution. Might be useful for anyone.

function hook_mail_alter(&$message) {
  if ($message['id'] == 'contact_page_mail') {
	  
	  require_once __DIR__.'/vendor/autoload.php';

	      $request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
		$data = $request->request->all();
		var_dump($data);
  }
}

This is giving me all the fields values of Contact form.

M.P’s picture

Hi, is there a twig template way to access form element and style them?
I did try form--personal.html.twig, but no success.(personal is id for default contact form)