Search code examples
drupal-7drupal-fapi

Show same form many times on one page (D7+formapi)


I'm trying show on views (each row) my custom form. It works, but the form doesn't work proper. I need to give to each form different ids.

hook_forms should help me, but I cannot manage how to use it. If I put print $form into it, I still cannot see my forms.

I'm calling my form like this from the template file:

$form1 = drupal_get_form('votingform_create_decision_form_' . $node->nid, $node->nid);
print drupal_render($form1);

Solution

  • Now I got it working:

    function hook_forms($form_id, $args) {
    
      if ($args[0] == 'mymodule_form_') {
        $forms['mymodule_form_' . $args[1]] = array(
          'callback' => 'mymodule_form',
          'callback arguments' => array($args[1]),
        );
      }
    
      return $forms;
    }