Plupload Upload + Synchronous form question

孤街浪徒 提交于 2020-01-01 17:05:38

问题


I have a setup with a traditional form that's checked with jQuery Tools validator and submitted via POST. I like that this class does not require extra classnames or other superfluous metadata to validate, standard HTML5 attributes are enough.

I now would like to extend this functionality with the Plupload upload solution. I know that all modern upload solutions work via Ajax these days, so I was thinking about a setup in which the user fills out the form, puts files in the upload queue and then submits the form. The form submit would imply:

  1. Validation through jQuery Tools Validator...
  2. If validated, uploading all files in the upload queue... (to a temporary folder)
  3. If upload went well, actual submit of the form via POST and moving files from temporary folder to permanent location.

I had a similar setup in place with Uploadify, where the filenames where appended into a hidden input field after succesful upload. On submit of the form, I thus had all filenames via $_POST. However, there were conflicts between jQuery Tools Validator and Uploadify. That's why I'm now looking into Plupload.

My questions?

  1. What do you think of this setup? Is this a good strategy?
  2. How would I go about implementing this on a technical level?

Thanks.


回答1:


I've found the answer. Plupload has this very nice functionality built in. It is designed to fit into an existing form. It uses AJAX to upload the files, but it returns the results of the upload before posting the form synchronously. This way, on posting a form enriched with Plupload, you also have the result of the upload in your POST variables.

It isn't really clear in the documentation, but after you submit a sample form from the examples, it states:

"Uploading is a bit different than you might be used to, files are uploaded to the temp folder, then when the form is submitted you get all the info you need to move around the files to the correct location. It's designed this way to make it easier to just apply it to an existing form. The low level core API has support for both methods."

Very nice upload solution. Some minor issues here and there, but I'm sure PEBKAC



来源:https://stackoverflow.com/questions/5272055/plupload-upload-synchronous-form-question

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!