Jump to:

23480 Posts in 18951 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Set Email Address in Custom Form from SiteConfig

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

Page: 1
Go to End
Author Topic: 545 Views
  • socks
    Avatar
    Community Member
    190 Posts

    Set Email Address in Custom Form from SiteConfig Link to this post

    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

  • 3dgoo
    Avatar
    Community Member
    133 Posts

    Re: Set Email Address in Custom Form from SiteConfig Link to this post

    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

  • socks
    Avatar
    Community Member
    190 Posts

    Re: Set Email Address in Custom Form from SiteConfig Link to this post

    That's exactly what I needed. Thanks!

    545 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.