2

I cannot add default value for file type in form builder. Theoretically it should work, when I use name of not-existing file, it throws an exception. However each time when I pass the form, I have to choose a file to upload.

My form builder:

    public function buildForm(FormBuilderInterface $builder, array $options) {
    $builder

            ->add('photo', 'file', array('label' => 'user.userinfo.properties.photo', 'data' => $builder->getData()->getPhotoAsFile()))
    ;
}
  • It is more of an html thing, than Symfony. Setting a default value for a file input is a security concern. You can check these answers for more information: http://stackoverflow.com/questions/1017224/dynamically-set-value-of-a-file-input – NoBBy Apr 27 '15 at 08:36
  • 2
    You could add a label that tells the user that a defualt file is selected, and if he doesn't select any, you set it when handling form submission – Bartłomiej Wach Apr 27 '15 at 09:13

0 Answers0