views:

30

answers:

1

Hi! I have some view which lists my module table entries. What is the most elegant way to attach a form below the view to add record? Waht I am trying to do know is:

  1. I created dedicated form in my module:

    function my_module_form_add_record($form_state) {
    form fields.....
    

    }

  2. I added to the view theme file:

    $add_form = drupal_get_form('my_module_form_add_record'); print $add_form;

But I do not like this solution for at least 2 reasons:

  1. I does not work ...

2. Even if it worked - it is depended on the theme file! So if I change the theme - functionality is crashed. I would like to find more elegant solution to attach form from custom module to the view.

I know of the existence of the "Views Attach" module but it has no option of adding custom forms. I know also of the existence of the Views Embedded form (and I am usig it) but it is only useful if you want to add form to the every row.

Seems the must be some solution to add record from the view page! Thanks you for help.

+1  A: 

you could use hook_views_pre_render:

This hook is called right before the render process. The query has been executed, and the pre_render() phase has already happened for handlers, so all data should be available.

Adding output to the view can be accomplished by placing text on $view->attachment_before and $view->attachment_after. Altering the content can be achieved by editing the items of $view->result.

Jeremy French
Thank you, but is this a template hook or module hook?
Lukasz
Looking at the views code it seems it is both.
Jeremy French
Update .. you are right. Thank You. I played with this hook in the template.php file first so I assumed it is only a theme hook. I was not aware till now hooks can be both theme and module.Thank You for this also.
Lukasz
That was a new one to me too. Not a bad idea in some cases.
Jeremy French