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.

Template Questions

problem getting CheckboxSetField data to display in email template


3 Posts   736 Views

Optic Blaze

4 December 2012 at 9:46pm Community Member, 162 Posts

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)

class EnquireForm extends Page {   

class EnquireForm_Controller extends Page_Controller {
public static $allowed_actions = array (
   public function 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 = '';
$To = '';
$Subject = 'Website Feedback';
$email = new Email($From, $To, $Subject);
//set template
//populate template
//send mail
//return to submitted message
$form->sessionMessage('We will be in touch','good');


Email template (

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


3 January 2013 at 5:58pm (Last edited: 3 January 2013 5:59pm), Community Member, 1 Post


Firstly in your .php I'd suggest removing the spaces from the array IDs, I couldn't get that working:

function ContactForm() {

// Dive Holidays //
$holidays = array(
'RedSeaNorth' => 'Red Sea North',
'RedSeaSouth' => 'Red Sea South'

In your template,, you can display the list of selected items in a CheckboxSetField like this (e.g. using an <ul>):

<% control DiveHolidays %> <!-- title of CheckboxSetField -->
   <% if RedSeaNorth %><li>Red Sea North</li><% end_if %>
   <% if RedSeaSouth %><li>Red Sea South</li><% end_if %>
<% end_control %>

It is a bit of a cludge but it works for me, does anyone else know a better way?


Optic Blaze

4 January 2013 at 1:08am Community Member, 162 Posts


I managed to find a better way. By adding the following, you implode the array and make it a string that you can use in your template:

// Implode checkbox values
if(isset($data['DiveHolidays'])) {$DiveHolidays= implode(',', $data['DiveHolidays']);} else {$DiveHolidays=' ';}

//populate template
$email->populateTemplate(array('DiveHolidays'=> $DiveHolidays));

Then all you have to do in the .ss template is call