Drupal drupal_get_form() First argument is expected to be a valid callback and your sure the form exists

Posted by: 
Dominique De Cooman

This means drupal cannot find your callback to your form.
Possible causes:

1) Drupal cannot find your function because the php file containing the function is not loaded.

I had this problem when I tried to call the 'simplenews_subscription_list_add' form with.

<?php
drupal_get_form
('simplenews_subscription_list_add');
?>

It failed giving this error:
warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'simplenews_subscription_list_add' was given in C:/wamp/www/bvl/includes/form.inc on line 366.

The solution: Look at the menu hook in the simple news module calling the fucntion.
<?php
  $items
['admin/content/simplenews/users/import'] = array(
    
'title' => 'Mass subscribe',
    
'type' => MENU_LOCAL_TASK,
    
'page callback' => 'drupal_get_form',
    
'page arguments' => array('simplenews_subscription_list_add'),
    
'access arguments' => array('administer simplenews subscriptions'),
    
'file' => 'simplenews.admin.inc',
    
'weight' => -9,
  );
?>

This means the form is inside a file called 'simplenews.admin.inc'. So you need to load the file:
<?php
module_load_include
('inc''simplenews''simplenews.admin');
return 
drupal_get_form('simplenews_subscription_list_add');
?>

Now your form will be loaded.

2) You made a typo :)

<?php
//this will work
drupal_get_form('myform');

//this wont
drupal_get_form('my_form');

function 
myform() {
  
//form defined here...
}
?>

Comments

Drupal drupal_get_form() First argument is expected to be a valid callback and your sure the form exists

I love you and want to have your babies..

Srsly, I was stuck for our on this for hours - thank you so much helpful internet stranger

Drupal drupal_get_form() First argument is expected to be a valid callback and your sure the form exists

Hi,

Really very helpful.Nice !!

Add new comment