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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Form Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Add a function to FormAction


Go to End


4 Posts   915 Views

Avatar
quanto

Community Member, 91 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, 1899 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, 91 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, 91 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...