By nilashis on
How to embed node add form in a block?
I have tried the following but it does not work. "free_listing2_node_form" is the form_id of the node add form I want to embed in this block.
If the approach below is right, I suspect problem in this statement "$block['content'] = drupal_get_form('free_listing2_node_form');"
Any help / direction is much appreciated!
<?php
function freelisting2_block_info() {
$blocks['neil_recent'] = array(
'info' => t('neil_Recent content'),
);
return $blocks;
}
function freelisting2_block_view($delta = '') {
$block = array();
switch ($delta) {
case 'neil_recent':
if (user_access('access content')) {
$block['subject'] = t('Recent content');
$block['content'] = drupal_get_form('free_listing2_node_form');
}
break;
}
return $block;
}
?>
Comments
I use the Form block module
I use the Form block module for such tasks
@nevets - Have you used Form
@nevets - Have you used Form Block for drupal 7 too? Looks like a dev release - does it work well for you with D7?
It has worked for me in
It has worked for me in Drupal 7.
This is an old thread, but
This is an old thread, but just in case it helps someone..
In the above code snippet, if you change drupal_get_form with node_add, it should work.
So:
$block['content'] = drupal_get_form('free_listing2_node_form');
Becomes:
$block['content'] = node_add('free_listing2_node_form');
-----
BeFused - Drupal tutorials
node_add() takes a content
node_add() takes a content type (not a form) as an argument and additionally it sets the page title which is probably not desired when using the form in a block.
This will work
Below is a demo function which returns the node type form.
Himanshu