call_user_func_array, a valid callback, 'node_form' was given

Niels Hackius - May 22, 2008 - 13:13

Dear fellow developers,
how do I go about fixing this error:

call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'node_form' was given in /htdocs/includes/form.inc in line 358.

What I do is:
* create a form using hook_form
* Use ahah to add x text-fields by having the user click on a button "add"
* Once I use the "preview" function the above error is displayed x-times

Thank you very much in advance for any help.

This is the function I use to render my ahah

<?php
function _lecture_ahah_appointments()
{
   
//get Post data
   
$form_state['post'] = $_POST;
     
$data = drupal_retrieve_form($_POST['form_id'],$form_state);

   
$form_build_id = $_POST['form_build_id']; //Cache ID
   
$form_state = array('submitted' => false);//reset form state
   
$cache = form_get_cache($form_build_id,$form_state);    //get cached version

   
$i = count($cache['appointments']);
   
//add the new textfield, with the inserted data to form

   
$cache['appointments'][$i]['who-'.$i] = array(
                                       
"#type" => 'textfield',
                                       
'#weight' => 9,
                                       
'#value' => $data['#parameters'][1]['post']['who'],
                                         );
   
//reset original form
   
$cache['appointments']['hinzu']['who']['#value'] = '';

   
//safe the form back to cache
   
form_set_cache($form_build_id,$cache,$form_state);

   
//Now alter the form
   
$cache['#post'] = $_POST;
   
$cache['#programmed'] = false;
   
$cache = form_builder($cache['form_id']['#value'] , $cache, $form_state);


   
//rebuild [appointments]-part, it will be replaced completly during in the form
   
$output = drupal_render($cache['appointments']);
    print(
drupal_to_js(array('data' => $output, 'status' => true) ) ); //bring everything back to drupal
   
exit();
}
?>

I am stuck

Niels Hackius - July 4, 2008 - 13:05

Does anyone have an idea?

It is possible...

dmitrig01 - July 4, 2008 - 16:12

... That node.module isn't being included on that page.

Try sticking this code in the top of your function:

<?php
if (!function_exists('node_form')) {
  include_once
'./modules/node.module';
}
?>

[Drupal++]

This doesn't help

Niels Hackius - July 10, 2008 - 12:02

This doesn't help unfortunately. The strange thing is, that the function is only missing upon "Previewing" the node. I also noticed that once all the other fields are filled out correct (e.g. title is not empty) and I press "Preview", all the ahah-content is gone.

Same problem

tomrenner - October 16, 2008 - 21:37

I have the same problem.This is what I do:

I have created a nodetype 'teilnahme' that includes a nodereference and a userreference.
When I try to

<?php
    $new_teilnahme_node
= array('type' => 'teilnahme');
    print
drupal_get_form('teilnahme_node_form', $new_teilnahme_node);
?>

I get the same warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'node_form' was given in drupal/includes/form.inc on line 366.

The funny thing is: once logged in as admin and I clear cache via devel, the warning disappears and the form is built correctly. Unfortunately only until I hit reload. Then I get the warning again :-(

Including node.module didn't help, either.

Anybody else concerned?

maybe you should reset node

mecano - November 9, 2008 - 00:22

maybe you should reset node types cache?
see this http://api.drupal.org/api/function/node_get_types

<?php$new_blognode = new

lukas.fischer - November 19, 2008 - 17:08

<?php
$new_blognode
= new stdClass();
$new_blognode->type = 'blog';
module_load_include('inc', 'node', 'node.pages');
$output .= drupal_get_form('blog_node_form', $new_blognode);
?>

works for me!

all the best
Lukas

--
www.netnode.ch

Yay!! works for me too,

dalad - December 25, 2008 - 22:53

Yay!! works for me too, thanks a lot!

works for me

Jerimee - May 21, 2009 - 23:41

good job - awesome!

how did you manage to get

benone - July 22, 2009 - 17:47

how did you manage to get this work ?

I have blog content type.
I have PHP filter.

I pasted this code to the body and I am getting a blank page.

Could you give me some quick advice what am doing wrong ?

B.

add echo $output; to the end

bfr - November 13, 2009 - 12:44

add
echo $output;
to the end of the code.

It works

denisanokhin - October 16, 2009 - 16:24

You can use shorter code to include nodes.pages.inc:

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

+1

Jay Matwichuk - November 13, 2009 - 13:14

+1

Just need to modify the submitter's uid

bigplanet - January 3, 2010 - 18:17

I have a very similar piece of code to the one provided by lukas.fischer (I landed on the post with the same problem as the original poster), the only difference is that I'm trying to modify the uid of the node on submission.

<?php
global $user;
module_load_include('inc', 'node', 'node.pages');
$node_sr = new stdClass();
$node_sr->type = 'service_request';
$output .= drupal_get_form('service_request_node_form', $node_sr);

return
$output;
?>

I have tried adding these lines to change the uid

//with $form being assigned
$form['uid']['value']=arg(1);

//tried
$node_sr->uid = arg(1);

//also tried
$node = array('uid' => arg(1), 'name' => $user->name, 'type' => $type);

I am running this code from a block, and it is properly rendering the form, but I can't seem to modify the uid of the node..?

Here is some background on what I'm doing with it...

I have a situation where I want a set of users (employees) to be able to create a node, but to replace the uid (user ID) with that of the users profile currently displayed.

In other words, I have a block that that calls a form for a content type. If an employee (uid = 20) goes to a clients page (uid =105), and fills out the form, I want the uid associated with the form to be the client's(105), not the employee's.

I'm using arg(1) to grab the Client's uid

 
 

Drupal is a registered trademark of Dries Buytaert.