Getting a page attribute from within a form block

Permalink 1 user found helpful
Hi!

I have a form block in a Global Area. The pages in my site have a page attribute called "email" with an email address in it (every page has its own specific email address). I would like the form block to send the messages to this email address. Is it possible? How would you approach this?

THanks!

jordif
 
jordif replied on at Permalink Reply 1 Attachment
jordif
Ok, so this was not that hard after all.

Imagine you have created a page attribute called "email" with an email address in it.

You can fetch the email address (or any page attribute) with the following code:

$pageEmailAttribute = Page::getCurrentPage()->getAttribute('email');


So you just need to use this variable as the recipient email address.

I've attached the code I used (you need to copy this file to /blocks/form/controller.php).