Form element's #required set to FALSE, but form submission still consider it as required 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' =&gt; array(
      'render element' =&gt; 'form',
      'path' =&gt; drupal_get_path('theme', 'mytheme') . '/templates',
      'template' =&gt; '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
Yes, theming the form only changes its markup. If you want to change the form you have to hook_form_alter. 

I once wondered how to add required styles to elements that weren't actually required. Your question just gave me the answer.