Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Form Questions /

Add a function to FormAction


Reply


4 Posts   631 Views

Avatar
quanto

Community Member, 81 Posts

21 March 2012 at 2:32am

I'm trying to put a Excel - export function behind a CMS-button, but when hitting the button, the page moves to /admin/EditForm (wich gives a 404 error). I use the following code:

class ExcelExport extends Page {
...
function getCMSFields() {
$fields = parent::getCMSFields();

$fields->addFieldToTab('Root.Content.Export', new FormAction('doExport', 'Export to excel'));
return $fields;
}

}

class ExcelExport_Controller extends Page_Controller {
public function doExport(){
...
FormResponse::status_message(sprintf('Export ok!' ),'good');
return FormResponse::respond();
}

Avatar
swaiba

Forum Moderator, 1808 Posts

21 March 2012 at 3:22am

Hi quanto,

I'm curious why you're not using ModelAdmin and the the "Export CSV" that comes right out of the box - assuming that the information you wish to export is within DataObjects...

However you might investigate "allowed_actions" as if you don't add the required action there the page will most likely give you a 404.

Avatar
quanto

Community Member, 81 Posts

21 March 2012 at 5:56am

I need a Excel export class because the file uses 2 sheets.

Thanks, I will try the allowed_actions option.

Avatar
quanto

Community Member, 81 Posts

22 March 2012 at 2:35am

allowed_action didn't work. I see in the source the "Export to Excel" button is not been surrounded by <form>. How do I fix this? so something like this:

$fields->addFieldToTab('Root.Content.Export', new Form('doExport', 'Export to excel')); //but with a button...