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

Access page values in controller: get email address from admin tab


Reply


2 Posts   1872 Views

Avatar
DeklinKelly

Community Member, 197 Posts

6 July 2009 at 11:31am

Edited: 06/07/2009 11:33am

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 %>

Avatar
DeklinKelly

Community Member, 197 Posts

8 July 2009 at 9:06pm

This works:

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