1

I have nearly the same problem than this : Multiple forms on single page?

But the answer is for an inclusion on a page template and I want to do the same on a node template where I can't use any incremental ID loop. I'm using Drupal 7.

3 Answers 3

1

In either Display Suite or a node template just call the forms using drupal_get_form each form will given a unique build_id and there should be no problem displaying any number of forms on the page.

hook_forms in this answer https://drupal.stackexchange.com/a/6230/3279 has nothing to do with your question. You don't need to worry about incremental form IDs or anything.

Here is an example of how to use a preprocess function for a Node (type): http://purencool.com/drupal-7-preprocess-tutorial-adding-variable-to-template this uses this Drupal API function https://api.drupal.org/api/drupal/modules!node!node.module/function/template_preprocess_node/7

Your code would look something like (this is example code not guarenteed to work):

function MYMODULE_preprocess_node(&$vars) {
  if ($vars['node']->type == 'MY_NODE_TYPE') {
    // link to webform paths.
    $vars['custom_form_links'] = implode(' ', array(l('Please Fillout Form 1', 'some/path/to/webform'), l('Please Fillout Form 2', 'some/path/to/webform2')));
    // Or just embed the forms.
    $form1 = drupal_render(drupal_get_form('myform1'));
    $form2 = drupal_render(drupal_get_form('myform2'));
    $vars['custom_forms_embed'] = $form1 . $form2; // You may want additional HTML wrappers, figure it out.
  }
}

Then in your themes template files for like node--YOURCONTENTTYPE.tpl.php you echo these new variables.

Display Suite makes all this a ton easier with Code Fields, or custom fields, and dynamic view_modes so you don't need to touch template files either ...

None of this code is guarenteed to run -- it's just a rough example.

0

I think you can get your form on template if you know their ids.

$form1 = drupal_get_form('form1_id');
$form2 = drupal_get_form('form2_id');

And then render by drupal_render()

drupal_render($form1);
drupal_render($form2);
2
  • Thank you for answer but I want to add each form at the bottom of a type of node. Each form is linked with the title of the node. So I have to code it in my node template one time and it will add the SAME form at the end of each node. So for example with a view, I will have multiple same form on my page but all are linked with the first node.
    – cocoggu
    Commented Jun 8, 2012 at 13:38
  • 1
    @cocoggu, you should update your question with information on comment, as other people might not read full comment of each answer. Commented Nov 20, 2013 at 6:13
0

Use Panels module. You can embed any number of webforms in a single page using panels module. Create a custom page and add existing nodes as content

1
  • Thank you but I think I have poorly explain my problem, see my comment on Shuaib Nawaz answer
    – cocoggu
    Commented Jun 8, 2012 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.