21285 Posts in 5732 Topics by 2602 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, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 1254 Views |
-
Access page values in controller: get email address from admin tab

6 July 2009 at 11:31am Last edited: 6 July 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 %> -
Re: Access page values in controller: get email address from admin tab

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');
}
}
| 1254 Views | ||
|
Page:
1
|
Go to Top |

