In Drupal 7, I have a preprocess function retrieving a form like so:

$contact = drupal_get_form('privatemsg_new');

$contact is then a fully populated form array with the right fields and elements. After that, I tried drupal_render and render, but neither one show a themed output in the node. What do I have to do to display the form?

1 Answer 1


The correct answer is to use drupal_render, which is used for render arrays like the form is. I tested this with a different form, and got the desired result so what you're doing should be right. Most likely you have a different error some where in your code causing this.

$html = drupal_render(drupal_get_form('form_id', $args)));
  • Doh! I just realized I am in a preprocess function, so it should have been $vars['contact'] with the render. Thanks for helping.
    – Kevin
    Commented Jul 29, 2011 at 17:30
  • if use above method, 'form' tag is not rendered
    – Guru
    Commented Jul 22, 2015 at 12:14
  • @Guru If the form tag is not rendered, then you have a different issue. I've done this many times and it have worked fine every time.
    – googletorp
    Commented Jul 23, 2015 at 12:26
  • Thanks @googletorp it is working fine. I've also faced another problem. ie, '#ajax' is not triggered when i rendered form by above method. Is any other solutions for this?
    – Guru
    Commented Jul 28, 2015 at 4:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.