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

quicksketch - April 18, 2008 - 06:15
Category:feature request» support request

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

stephen.colson - April 18, 2008 - 14:39

You can also use the nodereference cck type to load a specific webform.

#3

wpanssi - April 18, 2008 - 22:27

I'll try those. Thanks!

#4

wpanssi - April 18, 2008 - 23:00

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

stephen.colson - April 18, 2008 - 23:02

If you are taking an API route, check out hook_nodeapi and use the $op for view.

#6

quicksketch - April 19, 2008 - 01:25

<?php
$node
= node_load($nid);
$node->title = NULL;
print
node_view($node);
?>

#7

Jerimee - May 14, 2008 - 15:10

in Webform 2.x, there is an option to show the entire form in the teaser.

Where? I can't find it.

#8

quicksketch - May 14, 2008 - 15:31

Under "Webform advanced settings" on each node form, there is a checkbox labeled "Show complete form in teaser".

#9

Steve Dondley - May 27, 2008 - 13:45

Code snippet in comment #1 doesn't seem to work in a block for Drupal 6. How should that snippet get modified?

#10

Steve Dondley - May 27, 2008 - 13:53

Ignore last. I did not have php filter module turned on.

#11

meeotch - June 2, 2008 - 07:28

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):

  • warning: Invalid argument supplied for foreach() in /home/doctoris/public_html/redconnector/modules/node/node.module on line 521.
  • warning: implode() [function.implode]: Bad arguments. in /home/doctoris/public_html/redconnector/modules/node/node.module on line 525.
  • user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 query: SELECT n.nid, n.vid, n.type, n.status, n.created, n.changed, n.comment, n.promote, n.sticky, r.timestamp AS revision_timestamp, r.title, r.body, r.teaser, r.log, r.format, u.uid, u.name, u.picture, u.data FROM node n INNER JOIN users u ON u.uid = n.uid INNER JOIN node_revisions r ON r.vid = n.vid WHERE in /home/doctoris/public_html/redconnector/includes/database.mysql.inc on line 172.
  • warning: Invalid argument supplied for foreach() in /home/doctoris/public_html/redconnector/sites/all/modules/cck/fieldgroup.module on line 394.

**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

waynedrupal - July 13, 2008 - 13:36

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

waynedrupal - July 13, 2008 - 17:26

A little more guess work, and simply, it is as follows:

<?php
$node
= node_load(1);
$node->title = NULL;
print
node_view($node);
?>

#14

acstewart - August 25, 2008 - 23:24
Version:5.x-1.9» 5.x-2.1.3

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)

AttachmentSize
webform_with_block.patch 4.47 KB

#15

quicksketch - August 26, 2008 - 08:40
Title:Is it possible to show webform inside another node?» Show Webform as a Block or in another Node
Category:support request» feature request
Status:active» needs work

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

teck - September 4, 2008 - 09:43
Version:5.x-2.1.3» 6.x-2.1.3
Category:feature request» bug report

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

Summit - September 23, 2008 - 08:58
Version:6.x-2.1.3» 5.x-2.x-dev

Subscribing, this patch is for drupal 5 right?
greetings,
Martijn

#18

JordiTR - October 11, 2008 - 11:59

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

DaniOrama - October 16, 2008 - 12:31

Interesting... testing on D6

#20

quicksketch - January 11, 2009 - 05:06
Category:bug report» feature request

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

KrisBulman - February 23, 2009 - 13:29

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?

<?php
if (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

KrisBulman - February 23, 2009 - 13:30
Version:5.x-2.x-dev» 6.x-2.x-dev

#23

big67 - April 15, 2009 - 10:47
Version:6.x-2.x-dev» 6.x-2.6

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

mediamash - April 28, 2009 - 11:46

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

budda - April 30, 2009 - 23:40

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

quicksketch - May 1, 2009 - 00:01
Status:needs work» fixed

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

Yura Filimonov - May 10, 2009 - 12:15

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

quicksketch - May 10, 2009 - 19:43

The snippet in #1 still works in both Drupal 5 and Drupal 6.

#29

Yura Filimonov - May 11, 2009 - 02:50

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

System Message - May 25, 2009 - 03:00
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

#31

letsnurture - July 3, 2009 - 13:19

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

danieltome - July 31, 2009 - 06:12

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

levavie - September 27, 2009 - 00:56

The Webform block module now does the work.

 
 

Drupal is a registered trademark of Dries Buytaert.