drupaldrupal-render

Can I Omit <?php drupal_render($form); ?>


I have noticed that in your form theme file, whatever-form.tpl.php , when you omit

<?php drupal_render($form); ?> 

the only parts of the form that are rendered is what you specified - so I can also omit all of these lines:

<?php $form['title']['#access'] = FALSE; ?>
<?php $form['body']['#access'] = FALSE; ?>
<?php $form['menu']['#access'] = FALSE; ?>
<?php $form['revision_information']['#access'] = FALSE; ?>
<?php /* ... etc ... */ ?>

I wanted to do this so that when I install modules (say Books), I don't have to worry about going back to all of my custom forms and then adding the corresponding "hide this section!" line:

<?php $form['book']['#access'] = FALSE; ?>

Is it okay to omit drupal_render($form) ? Submission, Validation, etc will be okay?


Solution

  • The line you ask for, renders all form items that hasn't been rendered yet. This will most likely always include the form token a unique id for the form. Without it the form can't validate. This could cause a lot of trouble if removed.

    If you want to alter the form you should use hook_form_alter(). It allows you to based on the form id to remove/add/change form items. This is the Drupal way since it allows other modules to change forms when needed aswell.