3

I've created a content type for authenticated users to use, to create and edit & delete their own of. I have set up the permissions and can get access as a authenticated user to the forms directly via node/add/story & node/19401/edit.

Now i want to use the form on another page, to be used in a block within a panel.

$form = drupal_get_form('story_node_form');
return drupal_render($form);

using drupal_get_form doesn't seem to work correctly is there another function I should be using to pull in the form?

*UPDATE

I managed to get it to work using node_add

include_once(drupal_get_path('module','node') . '/node.pages.inc' );
return drupal_render(node_add('story'));

is there any security issues with this method?

1

This is no secure issues with this.

  • Drupal 6 return node_add('story')
  • Drupal 7 return drupal_render(node_add('story'))

Returns a node submission form.

for more information checkout the node_add() function

  • drupal 7, but drupal_get_form seemed to be missing much of the information and the render functions failed to render and returned errors instead. – bertsisterwanda Jul 14 '11 at 16:01
1

Actually what I need was to display a node addition form of any content type say 'page' on any custom callback, so that a user can use that form to submit and create a node. In order to get this thing working, we need to include node.pages.inc as this is required by a node form to get loaded successfully. Following code worked for me in drupal 6.

// required for Drupal 6

  module_load_include('inc', 'node', 'node.pages');  

  // which nodeform you want

  $node_type = 'YOURNODETYPE';

  $form_id = $node_type . '_node_form';

  // maybe add current users info

  global $user;

  // create a blank node

  $node->uid = $user->uid;

  $node->name = (isset($user->name) ? $user->name : '');

  $node->type = $node_type;

  // Invoke hook_nodapi and hook_node

  node_object_prepare($node);

  // Or you can also use an exiting node, for example 

  // $node = node_load(123);

  // and the display the form:

  $output = drupal_get_form($form_id, $node);
  • Hello and welcome. Code-only answers are a bit problematic. While it may answer the question, it does not explain how things works, and if it works, it will leave readers clueless about why and how. Could you expand your answer a bit, and add description of why are you doing what you're doing? – Mołot Nov 5 '13 at 12:53
  • @Molot - Explanation added. I hope this will help users in a better way. Thanks – Ata ul Mustafa Nov 19 '13 at 7:18
0

all you have to do something like that

  $node = new StdClass();
    $node->uid = $user->uid;
    $node->type = 'article';
    $node->language = '';
    node_object_prepare($node);
    $form = drupal_get_form('catering_information_node_form', $node);
    $output .= drupal_render($form);
    return output;

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.