0

I have a listing view with filters and a button to export the results to a CSV file. How can I send the view's arguments to my export callback after a user applies some filters?

2

Have you looked at Views Data Export. I've wired in a view to export on button click. You just build or modify a FAPI form to contain a button and give it the url of the view you want to output as csv.

In your case you'd pass the selected arguments into the view. You could use FAPI and Javascript to properly build the url and button action.

| improve this answer | |
  • I've managed to create the view for my export but I would like to add my button in the "exposed_form" $form and I'm not sure how can I achieve this. – bogtan Sep 4 '13 at 8:57
  • whats the name of the View you want to add the button to the exposed_filter (?) $form. What is your export view called?, does it have a page path url, what is that path ? – tenken Sep 4 '13 at 14:55
  • The path to my export view is <content_type>/export. And I was thinking that I can add the button through <mymodule>_form_alter() on views_exposed_form case, but I can't manage to find out how can I add a new button to the form. – bogtan Sep 5 '13 at 7:31
  • 1
    yes, use hook_form_alter ... your approach seems good. you add a button like $form['mybtn']=array('#type'=>'button', '#submit' => array('your_submit_function')); just be sure to add the button to the exposed form (which your logic should take care of as you described in hook_form_alter. – tenken Sep 5 '13 at 14:51
  • Thanks, this works just great. I was sure I couldn't find how to set the button, with #type, #submit and all attributes. – bogtan Sep 6 '13 at 7:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.