I created a form using Views and am implementing a module to use AHAH helper. It works great with a regular form such as 'user_register', but for some reason the error occurs on a form made using the Views module. The error message I get is:

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

Here is the module implementation:

function jeff_form_alter(&$form, &$form_state, $form_id)
{
	if ($form_id =='job_node_form')
	{
		build_myForm(&$form, $form_state);						
	}	
}

function build_myForm(&$form, $form_state) 
{
	// define our arrays
	$main_service_department = array('none' => t("Select something"), 'a' => t("a"), 'b' => t("b"), 'c' => t("c"));
		
        ahah_helper_register($form, $form_state);

       $form['service_type'] = array(
           '#type'   => 'fieldset',
           '#prefix' => '<div id="my-wrapper">', // This is our wrapper div.
           '#suffix' => '</div>',
           '#tree'   => TRUE, // Don't forget to set #tree!
       );
     $form['service_type']['main_type'] = array(
         '#type' => 'select',
         '#title' => t('User Type'),
         '#options' => $main_service_department,
         '#default_value' => 'none',
         '#ahah' => array(
             'event'   => 'change',
             'path'    => ahah_helper_path(array('service_type')),
             'wrapper' => 'my-wrapper',
             'effect' => 'fade',
    ),
  );
}

I should also mention that if I use the AHAH property without the AHAH helper module, it works OK.

Comments

jefflane’s picture

Sorry, I meant the form was created with CCK and is a content type. Nothing to do with Views.

zeropaper’s picture

The same happend to me, i just modified the module that way:

  // $form_state['storage']['#ahah_helper']['file'] has been set, to know
  // which file should be loaded. This is necessary because we'll use the form
  // definition itself rather than the cached $form.
  if (isset($form_state['storage']['#ahah_helper']['file'])) {
  	/*
    require_once($form_state['storage']['#ahah_helper']['#file']);
  	*/
  	require_once($form_state['storage']['#ahah_helper']['file']);
  }

and (nearly) everything went fine...
@wim i posted this modification in #380312: Only AHAH javasript settings are send back (sorry, I didn't saw this issue earlier) ;)

jefflane’s picture

I attempted the changes you describe in this post as well as your original post, but I am still getting the error:

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

I believe the problem has something to do with 'node_form' being passed into the call_user_func_array within the following line of code (from ahah_helper.module):

$settings = call_user_func_array('array_merge_recursive', $javascript['setting']);
zeropaper’s picture

You're right, indeed the problem has something to do with the 'node_form' function who can not be found because the required file (in this case 'node.pages.inc') isn't loaded.
If you look at line 366 of the 'form.inc' file, you'll find that the wanted function is the function called to generate the form (in this case node_form() ).

  // If $callback was returned by a hook_forms() implementation, call it.
  // Otherwise, call the function named after the form id.
  $form = call_user_func_array(isset($callback) ? $callback : $form_id, $args);

Personally, I had to put ahah_helper_register($form, $form_state); in a hook_form_alter() because my script isn't the form generator (I'm currently working on a CCK field)...

In your srcipt you may perhaps pass the $form_state as a reference (&$form_state) to fix that...

jefflane’s picture

Status: Active » Closed (works as designed)

That's it! Moving the ahah_helper_register function to within the hook_form_alter worked for me.

function jeff_form_alter(&$form, &$form_state, $form_id)
{
	if ($form_id =='job_node_form')
	{
		ahah_helper_register($form, $form_state);
		$output = jeff_form($form_state) + $form;			
		$form = $output;						
	}	
}

Thanks for your help.