sameera207
sameera207

Reputation: 16629

Retain the file field values with form validations

In my application I have a file upload (actually multiple file uploads), and I managed to do it without using a gem/plugin like (Ex: carrierware).

But when my form validation fails it loads the from data with error messages, but not the values in file_fields. My client wants to keep the values as it is when form validation fails.

I have search a bit and found out that for security reasons, its not allowed to set values to file fields. So can someone proposed me a possible workaround for this (to keep the selected file path when a form validation fails)

Please note that I'm not using Ajax form post here, this is simple default HTTP post

I'm running on ruby 1.9.2 and rails 3.0.0

thanks in advance

Upvotes: 1

Views: 904

Answers (1)

Bill
Bill

Reputation: 3209

It is not possible to do with what you are asking. Due to security reasons, the value of the upload field can not be set, or even styled with some browsers.

The best bet:

  • Upload the file before the validation, then discard if the user cancels.
  • Use ajax, or a fancy form of uploading. (Store path in hidden field, and then upload with some form of ajax/flash.)

Upvotes: 1

Related Questions