formular icon indicating copy to clipboard operation
formular copied to clipboard

Enctype should be set when file upload input is used

Open Titinux opened this issue 8 years ago • 3 comments

I'm using formular master branch

form(model, path) do
  f.input :image, type: :file
end

When using input element with type: :file, enctype="multipart/form-data" should be added to the form tag.

Titinux avatar Jul 24 '17 08:07 Titinux

Formular is not doing any magic, that's why you have to add the enctype="multipart/form-data" as argument in your form: form(model,url,enctype="multipart/form-data")

At least this is how I interpretate Formular, sometimes is a bit complicated but at least you have the control on what's going on!

Maybe Fran has a different opinion on that

emaglio avatar Jul 24 '17 23:07 emaglio

My opinion is that Formular should be clever but let you use elementary bricks if you want to. After it's all about to trace a line between cleverness and black magic. simple_form goes way too far but I'm about to finish converting my application from simple_form to formular and my forms are far more complex than before.

My personal line 😄 cleverness

  • add hidden input to cover the case where unchecked checkbox value is not send
  • enctype="multipart/form-data" when uploading file (you can't upload file if this isn't set)
  • ...

black magic (maybe extra gems or optional code without hard dependencies can cover this)

  • search into model for associations
  • auto labelling with i18n

Titinux avatar Jul 25 '17 08:07 Titinux

I agree with @Titinux there is little point in a form with a file input and no enctype. We already add the hidden input for checkboxes so I don't see why we shouldn't find a way to handle this.

fran-worley avatar Jul 25 '17 08:07 fran-worley