Jump to:

2011 Posts in 1436 Topics by 620 members

Form Questions

SilverStripe Forums » Form Questions » Add a function to FormAction

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

Page: 1
Go to End
Author Topic: 548 Views
  • quanto
    Avatar
    Community Member
    81 Posts

    Add a function to FormAction Link to this post

    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();
    }

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Add a function to FormAction Link to this post

    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.

  • quanto
    Avatar
    Community Member
    81 Posts

    Re: Add a function to FormAction Link to this post

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

    Thanks, I will try the allowed_actions option.

  • quanto
    Avatar
    Community Member
    81 Posts

    Re: Add a function to FormAction Link to this post

    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...

    548 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.