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 forum.silverstripe.org 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

Set Email Address in Custom Form from SiteConfig


Go to End


3 Posts   956 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!