Note that there are some explanatory texts on larger screens.

plurals
  1. POSymfony forms - remembering a previously selected file
    primarykey
    data
    text
    <p>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.</p> <p>If the form is not valid, I present it again to the user, to correct the erroneous field(s).</p> <p>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).</p> <p>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)?</p> <p>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.</p> <p>A snippet of my (action) code looks like this:</p> <pre><code>$files = $request-&gt;getFiles('foobar'); if(!empty($files) &amp;&amp; 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-&gt;form-&gt;setWidget('pict_path', new sfWidgetFormInputFile(array('default'=&gt;$pict_file))); } </code></pre> <p>Can anyone suggest how to correctly implement the desired behavior described above?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload