Jump to:

23487 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Access page values in controller: get email address from admin tab

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: 1786 Views
  • DeklinKelly
    Avatar
    Community Member
    197 Posts

    Access page values in controller: get email address from admin tab Link to this post

    I am creating a custom email form. I want the administrator to be able to change the email address and subject for form submissions. How can I access the values that the admin sets in the tabs for a page?

    PHP code

    <?php
    class ContactForm extends Page {
    static $db = array(
    'EmailToAddress' => 'Varchar(250)',
    'EmailSubject' => 'Varchar(250)'
    );

    static $has_one = array(
    );
       
    function getCMSFields() {
    $fields = parent::getCMSFields();
    $fields->addFieldToTab("Root.Content.Email", new TextField('EmailToAddress','Email address to send form submissions to)'));
    $fields->addFieldToTab("Root.Content.Email", new TextField('EmailSubject','Subject to be used for form submissions'));
    return $fields;
    }
    }

    class ContactForm_Controller extends Page_Controller {

       function submitForm() {
          if(!empty($_POST)) {
          mail(_EMAILADDRESS_SET_IN_EMAIL_TAB_, '_SUBJECT_SET_IN_EMAIL_TAB_', 'Message');
          }
       }
    }

    ?>


    .ss template

    $submitForm
    <% include Header %>
    <form action="$Link" method="post" >
    </form>
    <% include Footer %>

  • DeklinKelly
    Avatar
    Community Member
    197 Posts

    Re: Access page values in controller: get email address from admin tab Link to this post

    This works:

    class ContactForm_Controller extends Page_Controller {
    function submitForm() {
    if(!empty($_POST)) {
    mail($this->EmailToAddress, $this->EmailSubject, 'Message');
    }
    }

    1786 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.