在cakephp邮件模板中获取多个复选框

时间:2015-12-24 11:02:51

标签: php cakephp cakephp-3.0

将视图创建为

<?php $options = array("Eng_yes" => "English", "teg_yes" => "Telugu", "hin_yes" => "Hindi"); ?>
<?php echo $this->Form->input('read', array(
    'label' => __('Read', false),
    'type' => 'select',
    'multiple' => 'checkbox',
    'options' => $options,
)); ?>
<?php $options = array("Eng_yes" => "English", "teg_yes" => "Telugu", "hin_yes" => "Hindi"); ?>
<?php echo $this->Form->input('write', array(
    'label' => __('Write', false),
    'type' => 'select',
    'multiple' => 'checkbox',
    'options' => $options,
)); ?>
<?php $options = array("Eng_yes" => "English", "teg_yes" => "Telugu", "hin_yes" => "Hindi"); ?>
<?php echo $this->Form->input('understand', array(
    'label' => __('Understand', false),
    'type' => 'select',
    'multiple' => 'checkbox',
    'options' => $options,
)); ?>

创建控制器

public function enquiry_form()
{
    App::uses('CakeEmail', 'Network/Email');
    $useremail = $this->data['Feedback']['email'];
    $read = $this->data['Feedback']['read'];
    $write = $this->data['Feedback']['write'];
    $understand = $this->data['Feedback']['understand'];
    $Email = new CakeEmail();
    $Email->template('enquiry_form')
        ->subject($usertopic)
        ->to('xyz@xyz.com')
        ->from($useremail)
        ->viewVars(array('read' => $read, 'write' => $write, 'understand' => $understand))
        ->emailFormat('both')
        ->send();
    $this->Session->setFlash(__('Your Feedback has been sent'), 'flash', array('alert' => 'success'));
    $this->redirect($this->referer());
}

电子邮件模板文件

<?= $read ?>
<?= $write ?>
<?= $understand ?>

当我使用此代码发送邮件时,在邮件正文中

  

注意(8):数组转换为字符串[APP / View / Emails / html / enquiry_form.ctp,第1行]   代码上下文

<p><?=$read ?></p>
$viewFile = '/code/app/View/Emails/html/enquiry_form.ctp'
$dataForView = array(
'useremail' => 'test@gmail.com',
'read' => array(
    (int) 0 => 'teg_yes'
),
'write' => array(
    (int) 0 => 'teg_yes'
),
'understand' => array(
    (int) 0 => 'teg_yes'
)
)

如何在邮件正文中显示复选框值。

1 个答案:

答案 0 :(得分:1)

您正在尝试在enquiry_form.ctp模板文件中将数组打印为字符串。像这样使用。 电子邮件模板文件

<?= $read[0] ?>
<?= $write[0] ?>
<?= $understand[0] ?>

希望这能解决您的问题。