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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

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

Set Email Address in Custom Form from SiteConfig


Go to End


3 Posts   894 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, 135 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!