1

I need to use node_add(), but when I called it in my module I get the "undefined function" message.

So I'm trying to include it using module_load_include('inc', 'node', 'node.pages'), but I'm getting the error message:

Fatal error: Unsupported operand types in /var/www/vhosts/**.es/httpdocs/includes/common.inc on line 2946

Do you have any idea?

  • Maybe errors are below in your code. Try to comment your lines of code one by one and you will find which function called incorrect. – kalabro Sep 21 '11 at 13:15
  • nop because if i comment the line with module_load_include it works although I get the message "undefined function" – xger86x Sep 21 '11 at 13:53
  • But you could call node_add() in wrong way and got error when it was found – kalabro Sep 21 '11 at 14:54
1

I suggest you 3 method to add a node programatically

  • first method

    // 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 = array(
     'uid' => $user->uid,
     'name' => (isset($user->name) ? $user->name : ''),
     '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);
    
  • second method

     module_load_include('inc', 'node', 'node.pages'); 
     $node_type = 'YOURNODETYPE';
     $form_id = $node_type . '_node_form';
     global $user;
     $node = array(
    'uid' => $user->uid,
    'name' => (isset($user->name) ? $user->name : ''),
    'type' => $node_type,
    );
    node_object_prepare($node);
    print drupal_get_form($form_id, $node);
    
  • third method

    module_load_include('inc', 'node', 'node.pages');
    $form = node_add('nodetype');
    $output = drupal_render($form);
    
1

Maybe you are using an old version of PHP. Have you tried also running "php -l your_file.php". That will run just the parser to see if you have any php syntax problem.

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.