0
votes

I have a custom module with one form inside of it:

function emuforms_bistatistics_form($form, &$formstate){
    $form['#id'] = 'bistatistics';

    $form['headings'] = array(
        '#markup' => '<hgroup><h3>Instruction Statistics Form</h3>
        <h4>Please Fill Out Form Completely for Each Instructional Session.</h4></hgroup>'
    );  

   $form['general'] = array(
       '#title' => t('General'),
       '#type' => 'fieldset',
       '#collapsible' => TRUE,
       '#collapsed' => FALSE
   );
   ...etc
}

For this form I have created a menu link...

function emuforms_menu(){
    $items['emuforms'] = array(
        'title' => 'Forms and Tools 2',
        'page callback' => 'drupal_get_form',
        'page arguments' => array('emuforms_bistatistics'),
        'access callback' => TRUE,
        'type' => MENU_NORMAL_ITEM,
    );
    return $items;
}

...And a preprocess() function...

function emuintranet_preprocess_emuforms_bistatistics_form(&$variables){
    $variables['emuforms_bistatistics'] = array();
    $hidden = array();
    ...etc
}

...And a theme() function

function emuforms_theme(){
    return array(
        'emuforms_bistatistics' => array(
            'render element' => 'form',
        'template' => 'emuforms-bistatistics',
        ),
    );
}

Here's the Problem: The 'page arguments' => array('emuforms_bistatistics') follows the link to my custom .tpl.php file when I set it in this manner. However, I get several errors:

1) Notice: Undefined index: emuforms_bistatistics in include() (line 9 of /home/libintranet/htdocs/sites/all/modules/emuforms/emuforms-bistatistics.tpl.php).

2) Notice: Undefined index: emuforms_bistatistics in drupal_retrieve_form() (line 764 of /home/libintranet/htdocs/includes/form.inc).

3) Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'emuforms_bistatistics' not found or invalid function name in drupal_retrieve_form() (line 799 of /home/libintranet/htdocs/includes/form.inc).

On the other hand If I set 'page arguments' => array('emuforms_bistatistics**_form**'), I get no errors. HOWEVER, the path no longer follows to my .tpl.php file. Rather, it just displays my form directly from the _form function.

1

1 Answers

2
votes

Your page arguments passed to the drupal_get_form should be an existing function which builds & returns a form. If you want your form to use a custom theme (tpl), you can define it within the form by setting a #theme value.

Menu

function emuforms_menu(){
    $items['emuforms'] = array(
        'title' => 'Forms and Tools 2',
        'page callback' => 'drupal_get_form',
        'page arguments' => array('emuforms_bistatistics_form'),
        'access callback' => TRUE,
        'type' => MENU_NORMAL_ITEM,
    );
    return $items;
}

Form

function emuforms_bistatistics_form($form, &$formstate){
    $form['#id'] = 'bistatistics';
    $form['#theme'] = 'emuforms_bistatistics';

    $form['headings'] = array(
        '#markup' => '<hgroup><h3>Instruction Statistics Form</h3>
        <h4>Please Fill Out Form Completely for Each Instructional Session.</h4></hgroup>'
    );

   $form['general'] = array(
       '#title' => t('General'),
       '#type' => 'fieldset',
       '#collapsible' => TRUE,
       '#collapsed' => FALSE
   );
   ...etc
}