It looks like there is no direct way to save the outcome of <input type="email" multiple>
into Doctrine's simple_array
field, through Symfony 2 forms.
Details:
- My entity is of type
simple_array
: http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/types.html#simple-array - The FormType has
$builder->add('emails', EmailType::class, array('attr'=>array('multiple'=>'multiple')));
http://symfony.com/doc/current/reference/forms/types/email.html - Which renders (as expected):
<input type="email" multiple="multiple">
https://html.spec.whatwg.org/#e-mail-state-(type=email)
Now, when I enter two email addresses in the form (comma-separated, as expected by HTML5), the entity receives a comma-separated string.
However, when persisting into the simple_array
field, Doctrine expects an array, onto which it calls implode()
.
So the error message I get is: Warning: implode(): Invalid arguments passed
Reason: Symfony doesn't explode the comma-separated string into an array, before handing it over to Doctrine.
Solution: Do it manually:$entity->setEmails(explode(',', $entity->getEmails()));
So finally my question is: Is there an easier way for this?