symfony - Textarea field with data Transformer -
i have form textarea field(where user adds domains names, each per line) , data transformer transforms string array:
$builder->add( $builder->create('domains', 'textarea', [ 'trim' => false, 'constraints' => [ new assert\notblank(), new assert\all([ 'constraints' => [ new assert\notblank(), new domain(), new registerdomain(), ] ]) ] ])->addmodeltransformer(new arraytostringtransformer()) );
arraytostringtransformer
public function transform($values) { if (empty($values)) { return ''; } return implode($this->delimiter, $values); } public function reversetransform($string) { if (!$string) { return []; } return array_filter(array_map('trim', explode($this->delimiter, $string))); }
each domain should on new line. however, when string value on reversetransform value dont bring new lines. setted option trim false on field.
any idea why happen?
my delimiter is: '\n' tried '\r\n'.
well seems solution use double quotes , not single. so, if use "\r\n" works expected.
thanks.
newlines in input data can take 2 forms: \r
or \n
. split data using both of them.
return implode("\r\n", $values);
Comments
Post a Comment