Show Webform as a Block or in another Node
wpanssi - April 18, 2008 - 05:49
| Project: | Webform |
| Version: | 6.x-2.6 |
| Component: | Miscellaneous |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Description
Is it possible to somehow show webform as a content of another node? I would want to show my webform as a book page in my book. InsertNode -module allows me to show the title and the description of the webform but the form itself won't be seen.

#1
If you have php in the node, you should just be able to use:
<?php$node = node_load($nid);
print node_view($node);
?>
Also, what's probably happening is insertnode module is only showing the teaser. If there's an option to show the full node, use that instead and the full webform should appear.
One more option: in Webform 2.x, there is an option to show the entire form in the teaser.
#2
You can also use the nodereference cck type to load a specific webform.
#3
I'll try those. Thanks!
#4
Ok, using php snippet was easy! What if I would like to leave out the title of this node? A slick way to do that? I looked up the node_view function from API, but couldn't figure out how to leave out the title.
#5
If you are taking an API route, check out hook_nodeapi and use the $op for view.
#6
<?php$node = node_load($nid);
$node->title = NULL;
print node_view($node);
?>
#7
Where? I can't find it.
#8
Under "Webform advanced settings" on each node form, there is a checkbox labeled "Show complete form in teaser".
#9
Code snippet in comment #1 doesn't seem to work in a block for Drupal 6. How should that snippet get modified?
#10
Ignore last. I did not have php filter module turned on.
#11
Using the snippet given above in #1 to create a block containing my webform, I get the following error on pages displaying the block (and the block doesn't show up):
**EDIT: Scratch that - I'm a total dumbass. I forgot to replace $nid in the snippet with the actual node id of my webform. I'm going to leave this question here in case it helps future dumbasses who have made the same mistake.
#12
This is great, thanks.
It was posted that to have webform in node, just type the following with php selected as input format for that node:
<?php$node = node_load($nid);
$node->title = NULL;
print node_view($node);
?>
This is probably trivial, but I don't know exactly how to enter node id in there. Say my webform node id is: ?q=node/15 what would I put:
<?php$node = node_load($15);
$node->title = NULL;
print node_view($node);
?>
This does not work for me, so how would I do this is node id is node/15?
#13
A little more guess work, and simply, it is as follows:
<?php$node = node_load(1);
$node->title = NULL;
print node_view($node);
?>
#14
The attached patch adds a "Expose as Block" to the Webform Advanced fieldset in the webform edit page.
Once checking that, the webform will appear as an available block on admin/build/block.
Note that it's useful in this case to add a "thank you" message to the webform or redirect to an url.
(update.. just reuploaded the patch)
#15
This looks pretty good. I think a lot of users would find the functionality helpful so I'd like to be able to commit this feature improvement. However this expose a problem that the block is still displayed, even if the user is not allowed to fill out the form because of submission limits or access controls. The block should be hidden entirely, or continue to show but display one of the standard messages explaining why the form is no longer available.
Implementation-wise, can we not create a "block_id" counter, and instead just use the NID as the delta for blocks. This avoids adding another auto-increment column that will differentiate between the Drupal 5 and 6 version. Instead we add a column for just "block" that is a tiny (for mySQL, small for pgSQL) unsigned int of either 0 or 1.
If we can make those changes, please please port to Drupal 6 also to speed up the process for getting this into Webform.
#16
patching file webform.install
Hunk #1 FAILED at 23.
Hunk #2 succeeded at 955 with fuzz 1 (offset 173 lines).
1 out of 2 hunks FAILED -- saving rejects to file webform.install.rej
patching file webform.module
Hunk #1 succeeded at 336 (offset 95 lines).
Hunk #2 FAILED at 427.
Hunk #3 FAILED at 746.
2 out of 3 hunks FAILED -- saving rejects to file webform.module.rej
#17
Subscribing, this patch is for drupal 5 right?
greetings,
Martijn
#18
Hi you @ll,
there is a "Node as block" module quite useful for that purpose and for many other things:
http://drupal.org/project/nodeasblock
Basically it allows on "Content types" decide if such content type could have nodes to be shown as blocks and you activate it or not for each content type. The on node edition there is a textfield with several parameters.
#19
Interesting... testing on D6
#20
Moving to a feature request. I'm still open to including this as feature directly in Webform, since it requires special considerations when dealing with submission limits. The current patch in #14 doesn't really seem to have any advantage over the nodeasblock module JordiTR recommended in #18.
#21
I'm using webform in a block and validating the form with the snippet below. This gets the errors and posts them on the redirect page and clears the form once submitted, but is there a way to extract and display a user defined message (i.e "Thank You") in the same node after the form is submitted?
<?phpif (form_get_errors()){
drupal_set_message();
drupal_goto('node/19');
}
?>
Note:
I'm using this to display the webform in a block:
<?php$node = node_load(20);
print node_view($node, false, true, true);
?>
#22
#23
This can be done cleanly using views.
Add a "node type" view
Add a "block" display
Settings for the view: (I copy my settings below marking with *** the modified ones)
Display: Block
Basic settings
Name: Defaults
Title: None
Change settings for this styleStyle: Unformatted
Change settings for this styleRow style: Node *******
Use AJAX: No
Use pager: No
Items to display: 10
More link: No
Distinct: No
Access: Unrestricted
Exposed form in block: No
Header: None
Footer: None
Empty text: None
Theme: Information
Relationships: None defined
Arguments: None defined
Fields: The style selected does not utilize fields.
Sort criteria: None defined
Filters
Node: Type = Webform ********
Node: Nid = Your webform node ID ********
Do not forget to enable the block display in admin/build/block/list/your_theme_name
#24
when you click the submit button of you forgot to fill in an obligatory field, the form displays the webform-node instead of displaying the error/confirmation messages in the block-area. Ne1 knows a solution for that?
#25
Didn't see this thread previously and mad a module last November to do just this thing. Also addresses the issue in comment 24. Available now for download from http://drupal.org/project/webformblock
I've not tested it with the form submission limiter mentioned in comment 15.
#26
Excellent thanks budda! I'll feature the new module on the Webform project page. It'll be great to find any remaining problems with the approach. I'm still open to including it in the webform.module directly, but now we can work out all the kinks and decide if it's best left as a separate module or included in Webform. Thanks!
I'm moving this issue to fixed. Please report any issues with the webformblock.module in the issue queue for that project: http://drupal.org/project/issues/webformblock
#27
What's the correct PHP snippet or easiest way to insert a webform in a node now?
I tried the snippet above in D6 and it doesn't work.
Thanks.
#28
The snippet in #1 still works in both Drupal 5 and Drupal 6.
#29
That didn't work. I have PHP filter enabled and "show webform in teaser" checked, too.
For this particular case, I just entered the main content in the description field, but I'd still like to insert forms in nodes in the future.
I've inserted forms in nodes using the PHP code above in Drupal 5.7, but it just doesn't work in Drupal 6.11 with the 6.x-2.6 Webform version for me.
Thank you for your work.
#30
Automatically closed -- issue fixed for 2 weeks with no activity.
#31
Hi folk,
A very special thanks to www.ixis.co.uk.
This is what I was looking for.I just wanted to show contact-us like form in block of each page so that visitors of website do not need to go to contact us page.
Is "Node as block" module work same as "webformblock" module? I mean, can I get same functionality by use of "Node as block" module too?
Thanks,
Web-Farmer
@letsnurture.com
#32
You can override the validate and submit functions in form_alter and do a redirect.
To have this working, you will need clear the custom URL path of the webform.
Some code sample:
function MODULENAME_form_alter( $form_id, &$form )
{
if( $form_id == 'webform_client_form_998' )
{
$form['#submit']['MODULENAME_webform_998_submit'] = array();
$form['#validate']['MODULENAME_webform_998_validate_fix'] = array();
}
}
function MODULENAME_webform_998_submit( $form_id, $form_values )
{
return 'PATH/THAT/YOU/WANTED';
}
function MODULENAME_webform_998_validate_fix( $form_id, $form_values )
{
return 'PATH/THAT/YOU/WANTED';
}
I hope this helps someone.
If it doesn't work.. go to edit the webform and make sure URL path settings is empty.
cheers,
#33
The Webform block module now does the work.