[SOLVED] [Drupal Webform] drupal_get_form('webform_client_form_XXX') not working

| | 1 min read

If you are trying to load a Webform into a template variable to be printed in a block in your Drupal website, the obvious choice would be to use the drupal_get_form(webform_client_form_XXX) function with the machine name of the Webform as the argument. However this will not work as the logic is only partially correct. There are a few more steps prior to doing this. Read onto find out.

The form created by the Webform is technically a node. So we have to load the node containing the Webfrom first before we can do anything with it. The example code for doing it is shown below. The rest is done using drupal_get_form().

 $node = node_load(2721);
 $vars['template_variable'] = drupal_get_form('webform_client_form_2721',$node,array());

Hope that helps.

The easiest way to solve a Drupal issue is to hand it to the Drupal experts. We can provide a wide range of Drupal services to help you maintain and manage your Drupal websites. Get in touch with us to know more.