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've moved the forum!

Please use for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

calling a function onclick

Go to End


Guy Van Bael

Community Member, 61 Posts

29 January 2016 at 11:34pm

Edited: 02/02/2016 10:53pm

I 've written a function that creates a pdf from the page using dompdf module. It's working, but i would like it only to happen when a user clicks a button (or an ahref) in a template. Putting $showpdf (name of the public function in the class) in the template causes it ALWAYS to be triggered.
Can somebody shine a light on this?

UPDATE: I fixed it using a formaction. the only thing that doesn't work is the redirectback after the formaction when writing the pdf tofile. If choose to stream the pdf (and have it ready to download) instead of writing it to disk, everything is working as expected.
If i choose the 'tofile' option there are 2 issues. First the redirect that isn't working. The second issue is that every time the pdf is created, the cms creates a record in the files section which are imho completely redundant, because the file itself is being overwritten.

If someone has a better way of achieving this kind of functionality, i would be happy to hear from you!