I am trying to theme Contact form with template file, manipulating the contact form with form API, trying to hide the subject field and make it optional for submission.
$form['subject']['#required'] = FALSE;
hide($form['subject']);
I used dsm()
to confirm that the #required
is successfully set to FALSE
.
However, when I submit the form, it still ask me to fill in Subject field. (The cache has been cleared.)
These are the steps that I have followed:
In the template.php file I added the following code
function mytheme_theme() { return array( 'contact_site_form' => array( 'render element' => 'form', 'path' => drupal_get_path('theme', 'mytheme') . '/templates', 'template' => 'contact-site-form', ), );
I created the contact-site-form.tpl.php file with the following code
$form['subject']['#required'] = FALSE; hide($form['subject']); print drupal_render_children($form);
I cleared the cache