A lot of us really do need to just RTFM sometimes.
View full article »
Tag Archive: symfony
Another boring tech post, but I found it so difficult to find a simple, straight answer online that I have to post this.
All I wanted to do was make sure that when editing a record in Symfony using a page created using the admin generator, that it didn’t crack the shits if you didn’t edit an image that you’d previously uploaded. What if you just wanted to change the name of a recipe, but not the photo?
That’s a pretty simple request, right? I’ve seen posts advocating javascript and ajax, checkboxes that turn the input boxes on and off, extending the base Doctrine/Propel classes… wow.
Want to allow users to keep the existing file? Modify your *Form class and set the sfValidatorFile ‘required’ field to $this->isNew().
Eg.,
$this->setValidator(‘banner_file’, new sfValidatorFile(array(
‘required’ => $this->isNew(),
‘mime_types’ => ‘web_images’,
‘path’ => sfConfig::get(‘sf_upload_dir’).’/',
)));
Done. If the user edits the file, it will save. If they don’t, the original file will remain. If they create a new record, they’ll be forced to upload the file.
