I have the following example of a series of checkboxes on a form:
<?php
echo $this->Form->input(
'reason', array(
'label'=>false,
'type' => 'select',
'multiple' => 'checkbox',
'options' => array(
'Contact me' => 'Contact me',
'Brochure request' => 'Brochure request',
'Demonstration request' => 'Demonstration request',
'Training' => 'Training',
'Support' => 'Support',
'Other' => 'Other'
)
));
?>
This is then set as a variable in the controller like:
$this->set('reason', $this->data['Contact']['reason']);
And then in the email template I have tried doing this:
<?php var_dump( implode( ', ', $reason ) ); ?>
Which gives a result like: string(28) "Contact me, Brochure request"
How do I remove those quotation marks and the string(28) prefix?
What's the best way of doing this? Thanks
use the string helper/text helper. It has a built in toList
function.
// controller
App::uses('String', 'Utility');
echo String::toList($this->request->data['Contact']['reason']);
// or
// controller
$this->set('reason', $this->data['Contact']['reason']);
// view
echo $this->Text->toList($reason);
// outputs 1, 2, 3 and 4
assuming reason
is an array in the format:
array(
(int) 0 => '1',
(int) 1 => '2',
(int) 2 => '3',
(int) 3 => '4'
)
or just do a simple foreach($reason as $k => $v) { echo $v; }
Trying accessing your reasons like this in the view:
Controller
$this->set('contact', $this->request->data);
View
$contact['Contact']['reason'];