Return ListboxField Values in Email

Silverstripe Version:

3.1

Question:

I am trying to update my public contact form to include a ListboxField. I got the field to display correctly on the page; however, in the email that is sent the selected values do not return.

ContactForm.php

class ContactForm extends Form {

    public function __construct($controller, $name) {

		$fields = FieldList::create(
 // there are other fields in this
			ListboxField::create('MoreInformation', 'I would like more information about:', array(
				'Joining as a Consultant'=>'Joining as a Consultant',
				'Hosting a Gathering'=>'Hosting a Gathering',
				'Purchasing a Product'=>'Purchasing a Product',
				'Receiving Your Monthly Inspiration Living Newsletter'=>'Receiving Your Monthly Inspiration Living Newsletter'
			))->setAttribute('required','true')->setMultiple(true)
		);

		$actions = FieldList::create(
			FormAction::create('process','Submit')->addExtraClass('button small orange right')
		);

        parent::__construct($controller, $name, $fields, $actions);

		$this->setHTMLID('contact-form');
		$this->disableSecurityToken();

	}
	
	public function process($data, $form) {
		$contactPage = ContactPage::get()->First();
		$submission = new ContactMessage($data);
		$submission->write();
		$From = $data['Email'];
		$To = (!empty($contactPage->FormEmail) ? $contactPage->FormEmail : 'email@email.com');
		$Subject = "Website Contact Form";  	  
		$email = new Email($From, $To, $Subject);
		$email->replyTo($From);
		$email->setTemplate('ContactEmail');
		$email->populateTemplate($submission);
		$email->send();
		
	}

}

ContactMessage.php

class ContactMessage extends DataObject {
	private static $db = array(
		'FirstName' => 'Varchar(255)',
		'LastName' => 'Varchar(255)',
		'Address' => 'Text',
		'City' => 'Varchar(255)',
		'State' => 'Varchar(255)',
		'PostalCode' => 'Varchar(255)',
		'Email' => 'Varchar(255)',
		'Phone' => 'Varchar(255)',
		'Source' => 'Varchar(255)',
		'Message' => 'Text',
		'MoreInformation' => 'Varchar(255)',
	);
	
	private static $default_sort = 'Created DESC';

	static $summary_fields = array(
		'Created' => 'Created',
		'FirstName' => 'FirstName',
		'LastName' => 'LastName',
		'Email'   => 'Email',
	);

}

ContactEmail.ss

    <td>More Information: $MoreInformation</td>

I would guess that MoreInformation would be an array, so in your process() method you might need to do something like:

$submission->MoreInformation = implode(', ', $data['MoreInformation']);

Thank you for your response. I did try that, but it didn’t seem to make any difference.

We have decided to go a different direction to get this form to work like we need it to.