4

I have problem with file clear value. When submitting the form fails due to validation errors, the form type that have files (subtitle and watermark) are cleared and have to be selected again, but other type like text still keep value. It should remain in the same state as before trying to submit the form.

Bellow is my form type code:

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
        ->add(
            'newName',
            'text',
            [
                'mapped' => false,
                'required' => false,
            ]
        )
        ->add('subtitleFile', 'file')
        ->add('watermarkFile', 'file')
        ->add(
            'xAxis',
            'text',
            [
                'mapped' => false,
                'required' => false,
            ]
        )
        ->add(
            'yAxis',
            'text',
            [
                'mapped' => false,
                'required' => false,
            ]
        )
        ->add('start', 'submit');
}
vibol
  • 322
  • 4
  • 21

1 Answers1

4

And this is how HTML input file works in browser. There is no way to fill up these elements after page refresh. User has to select files again. This is for security reason.

Here is another stack post not related to Symfony.

HTML input file is basic uploading technique. You should use HTML5 or flash (but maybe rather no :)) to creating a better user experience. For example you can upload file immediately and store the information about temporary file to form element.

Community
  • 1
  • 1
kba
  • 4,190
  • 2
  • 15
  • 24