Submit form with checkboxes and display selected values in email template

Silverstripe Version:3

Question: I am trying to display selected checkboxes values in an email template but I am getting nowhere. I need some help. For info, the form works and I can display other pieces of data (textfields). Only the checkboxes are giving me trouble.

I have this in my form declaration

new CheckboxSetField(
                    $name = "DataRequired", 
                    $title = "Data Required", 
                    $source = array("1" => "alpha", 
                                    "2" => "beta", 
                                    "3" => "gamma", 
                                    ), $value = "" ),

I tried to display the values in my e,ail template using the following

                    <th>Deadline for request</th>


                    <th>Deadline for request</th>
                    <td><% loop $DataRequired%>$Me<% end_loop %></td>

I know the data is submitted because I can see it in the using debug

dataRequired =
1 =
2 =
3 =

Any help would be very appreciated

Me guessing you either didn’t pass the variables in the form of a ArrayData, Or, you haven’t given the email a template for it to use.

Below is a working version:



class AcknowledgementEmail extends Email

    public function __construct($member) {
        $from     =    Config::inst()->get('Email', 'noreply_email');
        $to       =    $member->Email;
        $subject  =    'Signup Confirmation';

        parent::__construct($from, $to, $subject);


            'MemberID'  =>  $member->ID,
            'baseURL'   =>  Director::absoluteURL(Director::baseURL())


(file location: at WWWROOT/mysite/templates/Email/

<!DOCTYPE html>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Signup confirmation</title>
    <p>Member ID: $MemberID</p>
    <p>base url: $baseURL</p>

If you don’t wish to use a customised email (extending Email class) class, then try $email->renderWith(‘dot_ss_template_name’); before you execute ->send();