I'm trying to load the user registration form into the front page (for some cool jQuery stuff) in a Drupal 7 installation. In Drupal 6, the code was as simple as this....
<?php
print drupal_get_form('user_register');
?>
However, in Drupal 7 it prints out an array of the form, and while I tried using render() on it and other attempts, it won't print that form out. The D7 API docs aren't real helpful as it shows no examples (unlike PHP / jQuery docs), and the linked form generation document doesn't really apply here as I'm not trying to do this in a module. Also as D7 is not well documented yet, Google hasn't been much help either. (Can't wait until the D7 Pro Development book is available.)
Does anyone know how to make this work in Drupal 7?
Comments
Came across something
Came across something interesting... http://coder1.com/articles/drupal-6-to-7-first-glimpse
Unfortunately, I am also trying
print drupal_render(drupal_get_form('user_register'));as that page suggested on the page.tpl.php and that is not working as well. Don't understand it...Oh, for crying out loud, I
Oh, for crying out loud, I sometimes hate change for the sake of change. Solved it, use this...
I should add that's just for the registration form, putting in any form ID should work fine with the above code (the D6/D7 rename threw me off).
Doesn't work for page node form
hmm, then why doesn't this work if I put it in a block (works for user registration but not fot page):
Get lots of php errors..
Greets Wappie
finally worked
Use this, it works
also look
http://api.drupal.org/api/drupal/modules--node--node.pages.inc/function/...
To get rid of these warnings
Works perfectly, Thanks!
Works perfectly, Thanks!
This works
This way works.
Thanks WebMaster.
Profile2 form id?
how do you display a profile2 form in a node using php? what form id do I use for profile2 registration forms?
This works. But for me it is
This works. But for me it is throwing a warning Strict warning: Only variables should be passed by reference in include() (line 45 of /var/www/foo/sites/all/themes/foo/templates/page.tpl.php). any ideas what is causing that? cheers, kevin
leymannx's example fixes this
Hi Kevin, If you separate the functions into two lines, as he did
Mini tutorial
Mini tutorial to use D7 config page, query a table, display the results in a table, with a pager, drupal_get_form and renderable arrays all rolled up into one neat little package.
I wanted to weigh in on this, even though it is [SOLVED], because this page does show up high in google results.
My code may not be perfect, or the best way to do this, but hopefully it saves people some time.
I hacked out a lot of code specific to my project, but here is working(after some tweaks) code:
You are my hero, I've been
You are my hero, I've been searching forever on how to place drupal_get_form within a page render array with other markup and your solution does just that. Thanks.
Works perfectly, Thanks!
Works perfectly, Thanks!
Printing a renderd form works
But If we return the same rendered form instead of print, It will display as normal page with theme.
Form Validation Error
If you are using form validation this will not work if you are printing the form directly in the template. To get the validation to work, assign the form to a variable in a preprocess function and then print that variable out in the template (see Jaypan's comment at form_set_error() should only). So for example in your template.php file you can put:
And then in your template, eg page.tpl.php you can then put:
@bmango, thanks. This info
@bmango, thanks. This info helped me a lot.
Argh! Yes! This solved a
Argh! Yes! This solved a really weird problem I was having where the form was only having ajax applied and working for anonymous users, but not when logged in. I'm not sure how this fixes it - but it does...