Sorry to ask such a lame question...judging from the previous issues a webform in 6.x and earlier could be embedded just like a node, using node_view(node_load($nid));

I'm trying to embed a webform in drupal 7 using drupal_render(node_view(node_load($nid))) and it prints out the node title and links, but not the webform.

Has the method for embedding webforms changed in 7.x?

As a side note, I also tried embedding it using the block like so:

<?php
$block = module_invoke('webform','block','view','client-block-2');
print $block['content'];
?>

But also had no luck with this method...not sure what i'm doing wrong here either.

Comments

quicksketch’s picture

Status: Active » Closed (won't fix)

This question is out of scope for the Webform queue.

Murz’s picture

vood002, did you solve your problem with any way? I have same problem and can't find the way how to solve it.

nylin’s picture

Maybe it's out of scope, but this is what you should do:

$block = module_invoke('webform', 'block_view', 'client-block-2');
print render($block['content']);
Murz’s picture

Thank's, this works normally!
And maybe you can help me with near problem to? I describe it at #1218420: Set webform form values via php on render state

tomassiro’s picture

Where do I insert this code?

$block = module_invoke('webform', 'block_view', 'client-block-2');
print render($block['content']);

nylin’s picture

You usually put that in your node template file at the place where you want the form to show up. Read more about template files and how to name them here.

/m

doublejosh’s picture

Would be nice to do it like this... http://drupal.org/project/node_embed

juziel’s picture

I had a problem like that, but I wanted to show separately (for design reasons) the body and the form of the webform content type in node--webform.tpl

In drupal 6 goes like this

print $node->content['webform']['#value']

In drupal 7 I used this code

webform_node_view($node,'full');
print theme_webform_view($node->content);

I spend like 2 hours figuring this out so i hope, it helps someone.

kpv’s picture

tnx

tike012’s picture

I accomplished the same using this code:

  print render(node_view(node_load(13157), 'full', NULL));

(13157 is the webform's nid).

What I would like to do is print only the form from the webform, and I have not yet figured out how to do that. Any help would be appreciated.

vernond’s picture

@tike012 - please don't crosspost (http://drupal.org/node/1312842#comment-5433422)

doublejosh’s picture

I've done this without PHP filter using Insert Block and Form Block.

varuntaliyan’s picture

Best way to accomplish the same in D 7 is by using the 'ADVANCED SETTINGS' provided by Webform module in D7, you just need to check the box for Available as block and it'll be available as block automatically.

Enzoyeeee .... :)

paniolo’s picture

Props to nylin for the answer!

meta_state’s picture

# This code worked perfectly for displaying a node within a block programmaticaly under Drupal 7
# Thank you tike012 !! :)

<?php
  print render(node_view(node_load(100), 'full', NULL));
?>

# Replace (100) with your custom node id #

-----------------------------
# To display a block within a node or another block under Drupal 7, you can use the following code:

<?php
$block = block_load('block', '100');
$output = drupal_render(_block_get_renderable_array(_block_render_blocks(array($block))));
print $output;
?>

# Replace '100' with your custom block id #

misscosmic’s picture

Go to the content from the Webform type that you created.
There are 4 options here -view-, -edit-, -webform-, -results-.

Go to Webforms >than underneath choose -Form settings-.
Scrol down to -Advanced settings-
Here you see the option -Available as block -.
And than ofcourse you can add this block to a region.
I made two blocks, one with text and the webform block, I placed them both in the same region on the same page.

This did it for me.
- - - -
Then I had the problem that once I filled out the form and -send-, I came upon a new (a confirmation) page. On this page was the link -go back to form-, when clicked this got me back to the form blóck, but not to the page the form block is on.
To make it so that after send, you stay on the same page, go to the same place as stated here above. And you'll see Redirection location and so check -no redirect-.

Hope this helps

firdous-1’s picture

Title: How to embed a webform in a node in drupal 7 » How to create form using node field?
Priority: Normal » Critical
Status: Closed (won't fix) » Active

Hi Guys!

Do let me know if u guys have the solutions for my problem.

Im doing real estate website. The situation is like this.... I want to create form for users to key in all the information about their house. I want to create this form using node because with the information that i get, i can simply filter it using views. Did anyone know what modules should i use?

quicksketch’s picture

Title: How to create form using node field? » How to embed a webform in a node in drupal 7
Priority: Critical » Normal
Status: Active » Closed (won't fix)

@firdous: This isn't a question suitable for the Webform issue queue. If you want to use nodes, make a node form and make it so that anonymous users can fill it out.

firdous-1’s picture

oh sorry.. but thanks alot. :)

fejn’s picture

Terrific explanation;it allowed me to find the path to the locations. I've been using a custom theme, so can't see the tabs (e.g., Webform), In D7, a normal user would get to the Available as a block setting as described by misscosmic. You can also get to the Form Settings page with the URL:
www.example.com/node/ID/webform/configure (Admin >> Content >> (your webform) >> Webform >> Form Settings)
(ID is the webform block ID -- get it from hovering over the edit button ) ; then proceed as above.

@misscosmic: your method works fine in Bartik and several other themes on a ~ fresh install, but I've run over myself somehow with custom theme & had to use this akward method there.

aiphes’s picture

#8 save me headache...thanks

nathalia252’s picture

#8 and #16 helped me a lot.

First enable webforms as a block:
- When creating the form and in the Webforms tab
- select the Form settings underneath
- Scroll down to -Advanced settings- and then you will see the option Available as block

Secondly within my node that I wanted to display the webform in I inserted where # is my webform id (you can find this out by hovering over the edit button when viewing the node or actually editing the node and looking at the address bar)

$node = node_load(#);
webform_node_view($node,'full');
print theme_webform_view($node->content);

I hope this full solution helps.

misscosmic’s picture

this is crazy! I cannot find the -new topic- on the forum.. so this is the only way I can ask that question. WHERE do I add a new topic..?!!

hockey2112’s picture

#3 worked great for me!

andrezstar’s picture

to #10
print render(node_view(node_load(13157), 'full', NULL));

I would even add something, not to have a warning like:
Strict warning: Only variables should be passed by reference in include()

It worked good for me. embedded a webform inside a node, and all things I altered from my customized module worked fine such as translations, class additions,...

$webform_node = node_view(node_load(13157), 'full', NULL);
print render($webform_node);

//its just getting the node variable first to render it afterwards

cumhur’s picture

#15 works for me (7.x-4.0-beta1)
Thank you :)

magendiran’s picture

Issue summary: View changes

Thanks, It's works...!!!

rakesh.gectcr’s picture

#3 works fine for me

<?php
$block = module_invoke('webform', 'block_view', 'client-block-2');
print render($block['content']);
?>
Paul Dudink’s picture

This solution might be fine if you - as a developer - create a single webform that must be printed in a single view.
However, in my case we have created a default webform (default fields) and the client can create as many webforms (events) with those same fields as he wants.
We cannot ask the client to create a block for each webform and besides: my template wouldn't know the blockID.

So: is there another solution? All I want is to render different page elements manually and also place the form in specific spot in the view.

DanChadwick’s picture

Re #29, sounds like you need to use a view. Support for views is available in the latest 7.x-4.x branch.

puidu’s picture

#22 worked for me

pawel.traczynski’s picture

To print a webform anywhere simply do:

<?php
$nid = YOUR_WEBFORM_NODE_NID;
$wnode = node_load($nid);
$form = drupal_get_form('webform_client_form_' . $nid, $wnode, array());
print render($form);
?>
ngocketit’s picture

#32 works.

ibozo’s picture

How print a webform as a block?
#32works as render but in the page where it's displayed, the form action is the nid of the currently page but not the url of the webform as a block

pyim’s picture

#8 worked for me, thanks for posting.

Nathan Tsai’s picture

If using

<?php
$block = module_invoke('webform', 'block_view', 'client-block-YOURid');
print render($block['content']);
?>

Remember to disable "available as a block" on the webform advanced settings.

jrwest_webguy’s picture

Number 3 and #8 work. It seems #22 is just #8 spread out over 3 lines, no?

If you want a (webform-)block within another block, use #3. As tike012 says, #8 renders the whole form -- including the title.

Number 3 works well, as far as I can tell. Does anyone see any problems, especially security-related, with it? Specifically, I've seen other threads that say you should never put php code in a block -- or, is that just an old wives tale?

tfranz’s picture

Another (flexible) approach without PHP is to use an entity reference field (https://www.drupal.org/project/entityreference) in your node form and select the webform you want.
By selecting the different view modes of your webform node type you can print out only the webform or the full node with body.

(To get rid of the title, you can change your view modes template, for example node--webform.tpl.php or node--webform--teaser.tpl.php)

myself@karolin-bierbrauer.de’s picture

Hi,

I inserted the code

$block = module_invoke('webform', 'block_view', 'client-block-204');
print render($block['content']);

into the drupal page I would like to create. The form is displaying but it is not executing.

Can you please help me here? Also how can I make the form smaller? It is too wide right now.

Thanks.

rajeev@blueappleonline.com’s picture

This works perfectly for me;

$block = module_invoke('webform', 'block_view', 'client-block-41'); print render($block['content']);