警告:在Drupal 7中缺少customvishal_form()的参数2:

时间:2011-12-27 07:42:58

标签: drupal drupal-7

我已经制作了一个自定义模块,它工作正常,直到我开始处理我的自定义主题。

一旦我转到我的自定义主题,我就会收到此错误

  

警告:调用customvishal_form()时缺少参数2   /home/vishal/Dropbox/sites/new/includes/theme.inc在1029行和   在customvishal_form()中定义(第441行)   /home/vishal/Dropbox/sites/new/sites/all/modules/customvishal/customvishal.module)。

您可以在http://www.iamvishal.com/dev/about-us

看到错误

我认为我的代码没有任何问题:

/**
* A simple form.
*/
function customvishal_form($form, &$form_submit) {
$form['customvishalactivate'] = array(
'#title' => t('Activate Preference'),
'#type' => 'radios',
'#options' => array('1' => t('Yes'), '0' => t('No')),
'#required' => TRUE,
);
return $form; 
}

调用
function customvishal_pref($arg1)
{
 // Here we willl make the form and save the data so when cron
 // runs we will check the users preference
 $build = array(
'header_text' => array(
  '#type' => 'markup',
  '#markup' => '<p>' . t('This page is where you add your preferences. Based on your      
  entered choices we will send you alerts ') . '</p>',
 ),
 'example_form' => drupal_get_form('customvishal_form'),
 );
 return $build;

 }

可能导致此问题的原因是什么?

干杯, 维沙尔

3 个答案:

答案 0 :(得分:3)

我有同样的问题

我这样调用了hook_form:

/**
 * Implements of hook_menu().
 */
function skupina_menu() {
  $items = array();
  $items['admin/config/people/skupina'] = array(
    'title' => 'Skupiny odborníkov',
    'description' => 'Prehľady návštev odborníkov',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('skupina_statistics'),
    'access arguments' => array('view statistics'),
    'file' => 'admin.inc',
    'file path' => drupal_get_path('module', 'skupina'), 
    'weight' => 1,
  );      
  return $items;
}

然后

/**
 * Prehlad navstev odbornikov - page
 */
function skupina_statistics($form, &$form_state) {

  $form = array();
  $form['skupina_obdobie'] = array(
      '#type' => 'select', 
      '#title' => t('Zmeniť zobrazenie'), 
      '#options' => skupina_get_zobrazenia(),
      '#description' => t('Zmení filtrovanie dát podľa zvolenej možnosti.'),
      '#required' => FALSE, 
  );  
  return $form;

}

我的问题是,该函数的名称中没有“_form”,因此它产生了这些警告。

因此,在我的情况下,该函数必须被称为"skupina_statistics_form

答案 1 :(得分:2)

当调用表单函数时,发送给它的唯一参数是表单变量。由于您的第二个函数参数没有默认值,因此显然会产生警告。

如果您从未在功能代码中使用它,您可以考虑将其删除或提供默认值。

e.g:

function customvishal_form($form, &$form_submit = NULL)

或者您可以考虑传递一个额外的参数。你可以这样做:

drupal_get_form('customvishal_form', $some_your_parameter);

答案 2 :(得分:1)

我想我知道答案。我遇到了同样的问题。

您的模块是否与自定义主题完全相同?我和我改变了我的主题名称,错误就消失了