I am using Symfony 1.3.2 on Ubuntu, and I have a form containing several widgets. One widget is sfWidgetFormInputFile, which allows the user to select an image.
If the form is invalid, I submit it to the user again to correct the error field.
The problem I ran into is that currently, when foem fails to verify (for some reason), the image file that was specified by the user is lost (i.e. he must select the file again).
How can I show the form to the user again, with the selected image file still there (so that they donβt need to select the file again)?
In my actions processing the POSTED form, I call getFiles ($ key) and then index the resulting array to get the file information and set the default value for the widget (see below). However, the rendered widget is empty (does not save the value of the path name to the previously selected file.
An excerpt from my (action) code is as follows:
$files = $request->getFiles('foobar'); if(!empty($files) && isset($files['pict_path'])){ $pic_info = $files['pict_path']; $originalName =$pic_info['name']; $type = $pic_info['type']; $tempName = $pic_info['tmp_name']; $size = $pic_info['size']; $pict_file = new sfValidatedFile($originalName, $type, $tempName, $size); $this->form->setWidget('pict_path', new sfWidgetFormInputFile(array('default'=>$pict_file))); }
Can anyone suggest how to correctly implement the desired behavior described above?
source share