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

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();
}

Comments

nhck’s picture

Does anyone have an idea?

dmitrig01’s picture

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

Try sticking this code in the top of your function:

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

[Drupal++]

nhck’s picture

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.

tomrenner’s picture

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

	$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?

mecano’s picture

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

lukas.fischer’s picture

$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

dalad’s picture

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

Jerimee’s picture

good job - awesome!

benone’s picture

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.

bfr’s picture

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

denisanokhin’s picture

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

module_load_include('pages.inc','node');
jaypan’s picture

+1

Contact me to contract me for D7 -> D10/11 migrations.

finaukaufusi’s picture

Excellent, this one works for me.

noctifer’s picture

This works beautiful. +1000!

bigplanet’s picture

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

lukas.fischer’s picture

You could try to change the UID with form_alter on presave op.

Cheers

Lukas Fischer
--
www.netnode.ch - Swiss Drupal Heros

Junro’s picture

Hello,

This code works great:

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

But i'm using a Node Reference field. How to automaticly set the node reference field with the actual node where is the edit form?

Any idea?

Thanks :)