2

我想知道是否可以在页面中插入节点。我使用 Drupal 7,但我找不到如何做到这一点。

有人有想法吗?我试图这样做:

    function test(){

       if (!function_exists('node_add')) {
        module_load_include('inc', 'node', 'node.pages');
       }

       print drupal_render(node_add('node_example'));

    }

我的表格显示但效果不佳。这是我的主题

4

1 回答 1

2

I hope I am understanding your question correctly. The answer to my comment did help! If it is a node form that you're trying to add to the menu, this is typically done with a hook_menu() function in Drupal. Here is some sample code to get you started

function YOURMODULE_menu() {

 // Here, substitute in the URL of your page.  It can be mymodule/add_content or whatever else you'd like
 $items['YOUR_PAGE_URL'] = array(
    'type' => MENU_CALLBACK,
    'title' => t('YOUR PAGE TITLE'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('your_node_function'),      // Here, you should put in the function that creates your node form
    'access arguments' => array('Administer content'),  // This is optional, you can require a user to have certain permissions set to access your page/form
 );

 return($items);

}

Remember to clear your cache before you test it!

Sample code in your function that is creating the form:

function your_node_function($form, &$form_state)
{
  $form['field_1'] = array(
   '#type' => 'textfield',
   '#title' => t('Field label'),
   '#description' => t('Help user understand what to input here'),
   '#required' => TRUE,
  );

  return $form;
}

See if you can see this tiny one-field form to get you started. This doesn't explain how to actually save the user data, etc because that is outside the scope of what a single answer here can provide, but this should help you get started on a form that's hooked up to the menu system....

I hope this helped!!!!

=================== EDIT ===================

Here is online documentation for the different types of form elements you can add to forms in Drupal: http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7

于 2012-07-23T15:01:20.007 回答