tirenweb
tirenweb

Reputation: 31709

About sfWidgetFormInputFileEditable

I'm tyring to use sfWidgetFormInputFileEditable to upload photos of hotels when I add a new hotel from my backend. This is the description of the widget:

The sfWidgetFormInputFileEditable is an input file widget, extending the sfWidgetFormInputFile widget to add the possibility to display or remove a previously uploaded file.

Option      Description
file_src    The current image web source path (required)

As you can see the parameter "file_src" is required, but when I create a new hotel I don't have any "current image web source path" for a new hotel..

What should I do, create a new class based on sfWidgetFormInputFileEditable whose option "file_src" is not required? What do you think is smart solution?

sf 1.4

Javi

Upvotes: 1

Views: 1679

Answers (1)

dxb
dxb

Reputation: 931

This parameter is used only in edit mode... so, you can fill it with the path of the future image, like this:

$this->widgetSchema['cover'] = new sfWidgetFormInputFileEditable(array(
  'label'     => 'Company logo',
  'file_src'  => '/uploads/covers/'.$this->getObject()->getCover(),
  'is_image'  => true,
  'edit_mode' => !$this->isNew(),
  'template'  => '<div>%file%<br />%input%<br />%delete% %delete_label%</div>',
));

look at the edit_mode parameter based on the isNew form's attribute.

Upvotes: 3

Related Questions