views:

64

answers:

0

I am using Symfony 1.3.2 on Ubuntu and I have a form that contains several widgets. One widget is the sfWidgetFormInputFile, which allows a user to select a picture.

If the form is not valid, I present it again to the user, to correct the erroneous field(s).

The problem I am experiencing is that currently, when the foem fails to validate (for whatever reason), the picture file that was specified by the user is lost (i.e. they have to select the file again).

How can I show the form to the user again, with the selected picture file still there (so they dont have to select the file again)?

In my action that process the POSTed form, I call getFiles($key) and then index the retrieved array to get the file information, and setting the default value of the widget (see below). However, the rendered widget is empty (does not retain the value of the pathname to the previously selected file.

A snippet of my (action) code looks like this:

$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?