开发者

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; ?>

开发者_Go百科Is it okay to omit drupal_render($form) ? Submission, Validation, etc will be okay?


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.


Well, whatever theme you're using seems to be a bit screwy, because every line of code you listed above should not be in the theming layer.

But to answer your question, removing drupal_render($form) will probably cause your entire form to not show up. So no, submission and validation and such will not work, and the form probably won't even show up on the page when rendered in a browser at all.


The short answer is definitely no, you can't omit drupal_render($form), because it contains information essential for correct processing of the form.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜