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

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


Go to End


2 Posts   3392 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'); 
      } 
   }