您好我有一个Filed(使用select2插件多次选择),名称是,模板到,它将包含多个电子邮件地址:
//My FormType Is:
->add('sendToEmailAddress', 'choice', array(
'choices' => array('LOCATION_OWNER' => 'LOCATION OWNER', 'ENQUIRER' => 'ENQUIRER','ENQUIRY_HANDLER' => 'ENQUIRY HANDLER'),
'required' => true,'data' => '','attr' => array('multiple'=>true,'class'=>'emalandSmsSendTo')
))
//My Twig File
{{ form_label(form.sendToEmailAddress, 'Send To Email', {'label_attr': {'class': 'col-md-3 control-label'}}) }}
<div class="col-md-9">
{{ form_widget(form.sendToEmailAddress) }}
{{ form_errors(form.sendToEmailAddress) }}
</div>
//My Entity Is:
/**
* @var ArrayCollection
*
* @ORM\Column(name="send_to_email_address")
*/
private $sendToEmailAddress;
/**
* Set sendToEmailAddress
*
* @param Array $sendToEmailAddress
*/
public function setSendToEmailAddress($sendToEmailAddress)
{
$this->sendToEmailAddress = new ArrayCollection($sendToEmailAddress);
// $this->sendToEmailAddress = $sendToEmailAddress;
return $this;
}
/**
* Get sendToEmailAddress
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getSendToEmailAddress()
{
return $this->sendToEmailAddress;
}
我想将多个选定值存储到单个字段“sendToEmailAddress”中作为序列化数组。但是在发布时,这个字段无法发布多个字段,它只发布一个字段。
请指导我在此遗漏的内容。
提前致谢
答案 0 :(得分:0)
在您的FormType中,'multiple'=>true
不应位于attr。
->add('sendToEmailAddress', 'choice', array(
'choices' => array('LOCATION_OWNER' => 'LOCATION OWNER', 'ENQUIRER' => 'ENQUIRER','ENQUIRY_HANDLER' => 'ENQUIRY HANDLER'),
'required' => true,
'multiple'=>true,
'data' => '',
'attr' => array('class'=>'emalandSmsSendTo')
))