Hi there,
I have a custom email form that i am building and i am having some hassles. I make use of CheckboxSetField for the visitor to select a couple of options. My problem is that when the email template form tries to process the data i get an error message:
Uncaught Exception: Object->__call(): the method 'fortemplate' does not exist on 'ArrayData'
I am guessing that because the $DiveHolidays object is an array and not a string, the template does not like it.
See code below
-------------------------------------------------------------------------------------------
Email form (mysite/code/EnquireForm.php)
--------------------------------------------------------------------------------------------
<?php
class EnquireForm extends Page {
}
class EnquireForm_Controller extends Page_Controller {
public static $allowed_actions = array (
'ContactForm'
);
public function init() {
parent::init();
}
function ContactForm() {
// Dive Holidays //
$holidays = array(
'Red Sea North' => 'Red Sea North',
'Red Sea South' => 'Red Sea South'
);
// Create fields
$fields = new FieldList(
new TextField('Name', 'Your name and surname*'),
new TextField('Tel', 'Your contact phone number*'),
new EmailField('Email', 'Your email address*'),
new TextareaField('Comments','Your query/comments*'),
new CheckboxSetField( 'DiveHolidays', 'Dive Holidays', $holidays)
);
// Create action
$actions = new FieldList(
new FormAction('SendContactForm', 'Submit')
);
// Create Validators
$validator = new RequiredFields('Name', 'Email', 'Comments');
return new Form($this, 'ContactForm', $fields, $actions, $validator);
}
function SendContactForm($data, $form) {
$From = 'test@test.com';
$To = 'client@client.com';
$Subject = 'Website Feedback';
$email = new Email($From, $To, $Subject);
//set template
$email->setTemplate('ContactEmail');
//populate template
$email->populateTemplate($data);
//send mail
$email->send();
//return to submitted message
$form->sessionMessage('We will be in touch','good');
Controller::curr()->redirectBack();
}
}
---------------------------------------------------------------
Email template (ContactEmail.ss)
---------------------------------------------------------------
<h1> Your website has generated the following feedback: </h1>
<p>Name: $Name </p>
<p>Contact number: $Tel </p>
<p>Email:$Email </p>
<p>Holidays:$DiveHolidays </p>
<p>Comments:$Comments </p>