Plupload Upload + Synchronous form question

2019-04-14 02:19发布

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条回答
Lonely孤独者°
2楼-- · 2019-04-14 02:54

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

查看更多
登录 后发表回答