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.

General Questions

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

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

Set Email Address in Custom Form from SiteConfig


Reply

3 Posts   551 Views

Avatar
socks

7 May 2012 at 11:19am Community Member, 190 Posts

Instead of coding the email address into the doContactForm code, I'd like to be able to change it via the CMS in SiteConfig.

I understand how to do it if the form processor and database field are in the same Class…

public static $db = array(
   'MailTo'=> 'Text'
);

function doContactForm($data, $form) {
   //Set data
   $from = $data['Email'];
   $to = $this->MailTo;

}

So what's the best way to reference "MailTo" if that field was added to SiteConfig and the form processor was on Page.php?

Thanks

Avatar
3dgoo

7 May 2012 at 4:44pm (Last edited: 7 May 2012 4:46pm), Community Member, 133 Posts

Hi Socks,

Call this from inside your function:

function doContactForm($data, $form) {
   $config = SiteConfig::current_site_config();

   //Set data
   $from = $data['Email'];
   $to = $config->MailTo;
   …
}

This came from here:
http://doc.silverstripe.org/sapphire/en/reference/siteconfig

I hope this helps.

Cheers

Avatar
socks

8 May 2012 at 8:13pm Community Member, 190 Posts

That's exactly what I needed. Thanks!