symfony - Upload profile picture -
i want allow user change profile picture. followed symfony2 documentations, it's working. problem is, can't call form using {{ form_widget(form.file) }}
must use {{ form_widget(form) }}
. it's annoying because have other value in formbuilder
, want able custom every fields in twig.
this formtype.
<?php namespace l3o1\userbundle\form\type; use symfony\component\form\abstracttype; use symfony\component\form\formbuilderinterface; use symfony\component\optionsresolver\optionsresolverinterface; class profilepictureformtype extends abstracttype { public function buildform(formbuilderinterface $builder, array $options) { // add custom field $builder->add('file', 'file', array( 'required'=>false)) /*->add('aboutme', 'textarea', array( 'attr'=>array( 'rows'=>4, 'cols'=>50 ), 'required'=>false))*/ ; } public function setdefaultoptions(optionsresolverinterface $resolver) { $resolver->setdefaults(array( 'data_class' => 'l3o1\userbundle\entity\user' )); } public function getname() { return 'l3o1_user_profile'; } }
if have error when try {{ form_widget(form.file) }}
share us.
if {{ form_widget(form.file) }}
doesnt save file problem must missing token or missing enctype form :
<form id="someid" action="{{somepath}}" method="post" {{ form_enctype(form) }}> {#your codes#} {{ form_widget(form._token) }} </form>