0

I'm trying to print Node Registration form so I used this code in node.tpl.php:

<?php
$form = drupal_get_form('node-registration-form');
print drupal_render($form);
?>

I've also tried id node_registration_form but it didn't work. Any ideas why?

EDIT 1: Ok, so i used this in template.php:

function mytheme_preprocess_page(&$vars){
  $myspecialform = drupal_render(drupal_get_form('node_registration_form'));
  $vars['node_registration_form'] = $myspecialform;
}

and print $myspecialform; in node.tpl.php and it works but i got this error now:

Fatal error: Call to a member function capacity() on null in C:\xampp\htdocs\dev\sites\all\modules\node_registration\includes\node_registration.forms.inc on line 676

Should i alter the form in template.php and add capacity input?

EDIT 2:

Nevermind guys, this module provides a node registration form block. I'm blind :) But thanks for help!

  • Never ever use drupal_get_form in TPL! – Mołot Sep 11 '15 at 16:07
  • Can you explain me why? Thanks – user504944 Sep 11 '15 at 16:21
  • First, I was told so by the guy who wrote this function. Second - because templating stage is far to late to create content that has to be processed. – Mołot Sep 11 '15 at 16:32
  • please edit your question with changes. It's OK as nobody answered yet. – Mołot Sep 11 '15 at 16:39
  • If the form is the only thing on the page you should be using hook_menu (and it's a config page or something not content). Otherwise use blocks or panels or something. This should not need to be rendered in a tpl or preprocess to display. – sareed Sep 11 '15 at 16:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.