Hi everybody.
I've got a simple contactform on a staff page. The goal is to enable the frontenduser to sent a mail directly to the staffmember of the company.
So i tweaked arams tutorial dataobjects as pages a little. I added a contactform and wanted to extract the staffmembers mailadress via hiddenfield.
This is my code so far
...
class StaffPage_Controller extends Page_Controller {
//add our 'show' function as an allowed URL action
static $allowed_actions = array(
'show',
'ContactForm'
);
function ContactForm() {
// Create fields
$fields = new FieldSet(
new TextField('Name', 'Ihr vollständiger Name *'),
new EmailField('Email', 'Ihre Mailadresse *'),
new TextField('Phone', 'Eine Rückrufnummer'),
new TextareaField('Comments','Ihre Nachricht *'),
new HiddenField('StaffMail', '', $this->StaffMember->Mail) //$this->ID
);
// Create action
$actions = new FieldSet(
new FormAction('SendContactForm', 'absenden')
);
// Create Validators
$validator = new RequiredFields('Name', 'Email', 'Comments');
return new Form($this, 'ContactForm', $fields, $actions, $validator);
}
function SendContactForm($data, $form) {
//Set data
$From = $data['Email'];
$To = $data['StaffMail'];
$Subject = "E-Mail vom persönlichen Kontaktformular der Webseite";
$email = new Email($From, $To, $Subject);
//set template
$email->setTemplate('ContactEmail');
//populate template
$email->populateTemplate($data);
//send mail
$email->send();
//return to submitted message
Director::redirect($this->Link("?success=1"));
}
public function Success()
{
return isset($_REQUEST['success']) && $_REQUEST['success'] == "1";
}
//Show the StaffMember detail page using the StaffPage_show.ss template
function show()
{
.
.
.
}
//Get the current staffMember from the URL, if any
public function getStaffMember()
{
.
.
.
}
//Return our custom breadcrumbs
public function Breadcrumbs() {
.
.
.
}
}
Formgeneration and validation works as expected. With firefox i'm able to inspect the hiddenfield value. The value is seeded with the right mailadress (given by the DOM via Backend) of the member. But, there's this error [Notice] Trying to get property of non-object. Whats wrong with that?
Thanks for your help. Pipifix
EDIT: Obviously this code '$this->StaffMember->Mail' isn't correct? Additional question: is it possible to set the mailto with this code? $To = $data['StaffMail'];