function ava_form_alter($form_id, &$form)
{
	if(is_array($form['#after_build']))
	{
		$form['#after_build'][]='ava_form_check_callbacks';
	}
	else
	{
		$form['#after_build']=array($form['#after_build'], 'ava_form_check_callbacks');
	}
}

According to the FAPI docs #after_build needs to have an array as a value. I'm using AHAH Forms as an example for my new module (to see how they've implemented their own FAPI element property) and that module simply passes on a string as a value for #after_build. That caused the PHP errors below on my clean Drupal 5.3 install. After reading the docs again I decided to make sure the value passed on on to #after_build would be an array by using the code above. It's the else-statement that's causing problems, but I can't figure out what's wrong. The errors:

* warning: Invalid argument supplied for foreach() in /Users/bart/htdocs/ava/modules/system/system.module on line 1543.
* warning: ksort() expects parameter 1 to be array, null given in /Users/bart/htdocs/ava/modules/system/system.module on line 1549.
* warning: Invalid argument supplied for foreach() in /Users/bart/htdocs/ava/modules/system/system.module on line 1553.

Would anybody know what's wrong?

Comments

Folkert’s picture

try this in the if statement true state, and make clear if you talk drupal 6 (like in the title) or drupal 5 ;)

$form['#after_build'] = array('ava_form_check_callbacks');
hth,

xano’s picture

Sorry, it's Drupal 5.3. Don't know why I said D6....

Why change the code in the true state? That's not the part that's not working. With your line of code the already declared after_build callabcks will be erased. I'll be happy to try it, but I don't think it's going to work.

Folkert’s picture

in the false state that is i'm sorry. in de true state you clearly want to push another string into the form['#afterbuild']

Maybe better to check if isset instead of checking if the value is an array.

if(isset($form['#after_build']))
    {
        $form['#after_build'][]='ava_form_check_callbacks';
    }
    else
    {
        $form['#after_build']=array('ava_form_check_callbacks');
    }
xano’s picture

I just tested if using isset() rather than is_array() would work, but I keep getting the same errors.

Just a little sketch of the situation: #after_build is either set or it's not set. When set it's either a string or an array. First thing that needs to be done (as far as I can see it) is to check if #after_build is an array. It checks for #after_build's existence and its type. If it's an array a new row needs to be added containing a new callback (the if-statement). If it's not, it needs to become an array (the else-statement). The new callback is added as a row and the old string value is added, which is NULL or an actual string value.

Even when I copy the #after_build declaration directly from AHAH Forms I get errors, I've read the FAPI docs several times and I can't see what's wrong with this piece of code.

BTW: Hey F, didn't notice it was you until now :-P

Folkert’s picture

If #after_build is set it's an array all the time. Don't know how you came to think it could be either a string or an array but that's not correct, it's either not set or an array with function name / names