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   591 Views

Avatar
socks

Community Member, 191 Posts

7 May 2012 at 11:19am

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

Community Member, 133 Posts

7 May 2012 at 4:44pm

Edited: 07/05/2012 4:46pm

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

Community Member, 191 Posts

8 May 2012 at 8:13pm

That's exactly what I needed. Thanks!