Search code examples
drupalcontact-formhook-form-alter

hook_form_alter changes array, but is not rendering in contact form


I use hook_form_contact_site_form_alter to alter the Conact Form. Everyting works fine when I change the array, for example:

  $form['firstname'] = array (
    '#type' => 'textfield',
    '#title' => t('FirstName'),
    '#maxlength' => 255,
    '#required' => true

  );

dpm($form); shows me this:

enter image description here

So, thats perfect

... but nothing renders! Its still the good old default contact form: enter image description here

I was thinking, that maybe another hook overrides mine, or that I have to tell Drupal to rebuild the form. I haven't found anything usefuls in the API Reference yet.

Maybe somebody else had the same problem, or knows a good method to debug?

Thanks in Advance

btw. I had the contact_forms module installed, but uninstalled it again, maybe this is related.


Solution

  • When using form_alter, don't forget to pass the first argument as a reference (&$form) or your $form variable will not be modified once your function has been executed.

    function hook_form_contact_site_form_alter(&$form, &$form_state, $form_id) {
    
    }