I am trying to render a webform in code. I have the following:

$node = node_load(10971);
$submission = (object) array();
$enabled = TRUE;
$preview = FALSE;
$form = drupal_get_form('webform_client_form_10971', $node, $submission, $enabled, $preview);
drupal_render($form);

If I print_r the contents of $form, I see that my form is there in the array. But when I call drupal_render on it, the form doesn't appear on the page. I don't get an error or anything else that would tell me what is going wrong.

Any ideas?

Thanks,
Nathan

Comments

nathanatvscreen’s picture

Having dug in to this a bit more, the form array doesn't seem to have an #access element. This is causing drupal_render to just return nothing. Why would my webform array not have the #access element?

jaypan’s picture

It doesn't need to. The absence of an #access element means access is granted.

Try calling render() instead of drupal_render().

Contact me to contract me for D7 -> D10/11 migrations.

nathanatvscreen’s picture

Tried that; same result.

jaypan’s picture

Are you actually doing anything with that rendered form? And what is the context of this code? Where is it? How are you using it? Is this the complete code? etc.

Contact me to contract me for D7 -> D10/11 migrations.

Mike Vranckx’s picture

Don't forget to actually print out the renderable array:

print drupal_render($form);
nathanatvscreen’s picture

Thank you. I wasn't printing it.

print drupal_render($form); solved it.