5

Does anyone know how to create a node form for specific Content Types? Instead of clicking Content > Add Content > Content Type they can just, I don't know, go to the sidebar and fill out the info there.

This would be great for Content Types which allow Anonymous access like a Testimonials Content Type. There's a short something over at http://goo.gl/LMpSS but it doesn't really explain anything and leaves you wanting for more.

7

I'd recommend using the Form Block module.
This module simply exposes node forms in blocks. You'll get an extra set of options for each content type, which enables/disables the block.

If you need to do it programmatically, node_add() is the best way to go, as suggested by @kiamlaluno.

| improve this answer | |
8

You can use the code for node_add() as a guideline.

function mymodule_node_form($type) {
  global $user;

  $output = array();
  $types = node_type_get_types();

  if (isset($types[$type])) {
    $node = (object) array(
      'uid' => $user->uid,
      'name' => (isset($user->name) ? $user->name : ''),
      'type' => $type,
      'language' => LANGUAGE_NONE,
    );

    $output = drupal_get_form($type . '_node_form', $node);
  }

  return $output;
}
| improve this answer | |
  • Good answer, you can also use node_add() directly see my answer below. – chim Jul 24 '13 at 14:12
  • I had to add the line module_load_include('inc', 'node', 'node.pages'); in order to get this to work. – Felix Eve Dec 5 '13 at 10:30
1

Shamelessly lifted from SO:

https://stackoverflow.com/questions/5344754/drupal-7-how-to-display-node-add-sometype-form-on-another-page#answer-7740337

module_load_include('inc', 'node', 'node.pages');
$form = node_add('node_type');

Kudos to @"Marius Ilie"

| improve this answer | |
0

I didn't try, but I think that you have to create a display (block, content panel, view, etc) and put the drupal_get_form() call in this display.

You can create a display programmatically (hook_block_view() for example), or you can use the Views module. With this module you create a new view (at admin/structure/views), add a display ('block' for example), then you add 'a global text area' (in header or footer) where you past his PHP Code (don't forget to change the formater of the global text, 'Filtered HTML' to 'PHP Code'.

To finish, if you created a block, you can place it where you want (with the admin UI at admin/structure/block).

| improve this answer | |

Your Answer

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

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