The workflow of my site would be really improved if I could make an 'add a node' panel inside a template. Think like the 'quick reply' feature you see in some forums.

How could this be done? Obviously I can't node_load something that doesn't exist yet, nor include a .php file that's not called - I hoped drupal_get_form would help me out, but maybe I'm using it wrong, as I just can't get that to work. Has anyone else dealt with this or know of a good place to start?

Comments

nevets’s picture

You need to be able to specify the content type you want to add, for the example I use story but any valid content type (that you have installed) should work.

print node_add('story');

Worth a try at least.

Squidgy’s picture

Holy snap, I had no idea it was that easy! Thanks a great deal - I was just starting to look at a series of form_alters and other madness! It works just as well in content as it does in blocks.

There is one weird thing, which is that the page title seems to be overriden by the newly arriving edit menu, so I imagine I'll have to look into a way to unset that for good luck.

But dude, thanks.

heine’s picture

That is due to the following code in node_add:

  if (array_key_exists($type, node_get_types()) && node_access('create', $type)) {
    // Initialize settings:
    $node = array('uid' => $user->uid, 'name' => $user->name, 'type' => $type);

    $output = node_form($node);
    drupal_set_title(t('Submit %name', array('%name' => node_get_name($node))));
  } 

Workaround, store the previous title, then set it back:

$title = drupal_get_title();
/// node_add(...); here
drupal_set_title($title);

(disclaimer: untested, etc)
--
The Manual | Troubleshooting FAQ | Tips for posting | How to report a security issue.

smokingtrucks’s picture

I'm interested in how this might be accomplished inside a block. (I'm also interested in 'tracking' this thread, that's why I had to add my two cents!)