Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi. I would like to pass this JavaScript callback
init : {
FilesAdded: function(up, files) {
up.start();
},
}
using the '#plupload_settings'. Here is what I did, but it doesn't work and leads to JavaScript error. Is there any other way how to pass the callback to the init of Plupload?
$form['gallery_upload'] = array(
'#type' => 'plupload',
'#title' => 'Some title',
'#description' => 'Some desc',
'#upload_validators' => array(
'file_validate_extensions' => array('jpg jpeg gif png zip'),
),
'#plupload_settings' => array(
'runtimes' => 'html5,flash,html4',
'chunk_size' => '1mb',
'init' => 'FilesAdded: function(up, files){up.start();}',
),
);
Comment | File | Size | Author |
---|---|---|---|
#36 | 1804382_36.patch | 4.17 KB | slashrsm |
#26 | plupload_autostart.patch | 630 bytes | vladan.me |
#25 | plupload_autostart.patch | 458 bytes | vladan.me |
#24 | plupload_autostart.patch | 598 bytes | vladan.me |
#6 | plupload_autostart_1804382_6.patch | 473 bytes | slashrsm |
Comments
Comment #1
maxiorelOK, my workaround was to rewrite the parts of the module to use the jQuery UI version of Plupload and use the autostart option set to true. To bad the autostart doesn't work with pluploadqueue version.
Comment #2
slashrsm CreditAttribution: slashrsm commentedWhat about solutions proposed here? http://stackoverflow.com/questions/8137229/plupload-automatically-start-...
It would be nice to have autoupload option on Form element, though. We should only find some reliable, friendly and non-hacky solution.
Comment #3
maxiorelThat would be nice, I saw it already. But I think it is not possible to push the
init : {
FilesAdded: function(up, files) {
up.start();
},
}
from creating the form on PHP side. Or I do not know how to do it at least, as I was asking in my initial post.
Comment #4
slashrsm CreditAttribution: slashrsm commentedThat's probbably true. We could add something like #autostart to form element and handle this setting in js on our own.
Have you tried to push this setting as an array, instead of a string?
Comment #5
maxiorelSure, I've tried. Without success.
Comment #6
slashrsm CreditAttribution: slashrsm commentedI tried this just to see if I can get autostart working, but it doesen't. Are you sure the code you proposed works?
Comment #7
maxiorelI don't know already. I've ended up with rewriting the module to jQuery verison of Plupload and it works as excepted.
Comment #8
slashrsm CreditAttribution: slashrsm commentedCan you share the code so we can check if we can incorporate your solution into this module?
Comment #9
maxiorelHi, sorry for late answer. My solution is very dirty without any config options. But works well and the upload starts as soon as the files are added to the Plupload area.
For the 7.x-1.3 version:
- plupload.module - changed the function a little bit. On the first lines, there are some jQuery UI call via drupal_add_library. The two rows with $library_path are changed.
Next, the plupload.js needs the change around the line 47:
Comment #10
mohit_aghera CreditAttribution: mohit_aghera commented@maxiorel
I am also using 7.x-1.3 version of the module.
If i am using HTML5 version then also it is not working. Is there any workaround for that ?
I changed as per your suggestion and cleared the cache too.. but it doesn't work for me..
Still i have to click upload button to upload the file.
I got this link from Plupload forums. http://www.plupload.com/punbb/viewtopic.php?pid=13150
Can we use the approach suggested by djdon11 user ?
Comment #11
mohit_aghera CreditAttribution: mohit_aghera commented@slashrsm
Did you got any solution for the auto upload ?
I am using html5 runtime, and the solution suggested by @maxiorel doesn't work for me.
I am trying to figure it out, let me know if you found something helpful.
Comment #12
slashrsm CreditAttribution: slashrsm commentedSolution in #9 should work. We cannot commit this solution, though.
Comment #13
mohit_aghera CreditAttribution: mohit_aghera commented@Slashrsm
Can you please tell me which version of plupload you are using ?
Actually i am using the same code which you suggested me, but it is not working any more..
And i don't see any javascript or any other error too
Comment #14
slashrsm CreditAttribution: slashrsm commentedWhy do you think that mu Plupload version is important?
Comment #15
mohit_aghera CreditAttribution: mohit_aghera commentedProbably there might be some issue from the plupload library version.. I am using 1.5.7
Comment #16
slashrsm CreditAttribution: slashrsm commentedI am not having any problems with the patch, as I am not even using it. I am just saying that if we want to get something like this into official code it needs to be prepared in a way that will provide configurability and backward compatibility.
Comment #17
drupalina CreditAttribution: drupalina commentedI tried #9 and the entire plupload drag-n-drop box had converted to drupal's usual file upload interface. So it didn't work.
Can someone please post a working solution?!? In this day and age end-users expect not only a multiple upload but also auto-upload!!!
Comment #18
mohit_aghera CreditAttribution: mohit_aghera commented@drupalina Do you want to multiupload files with plupload only ? There is another solutions using Drupal form API you can try it out that. I used this solutions as i was not able to upload/multiupload files using plupload
http://mohitaghera.drupalgardens.com/content/multiple-file-upload-usind-...
Comment #19
drupalina CreditAttribution: drupalina commented@mohit_rocks thanks for the link. What I want is not just multi-file upload, but also so that the "Start upload" button in plupload disappears and as soon as the files are selected the upload process should start immediately on its own! Automatically. My end-users are driving me crazy with stupid questions like "Oh, I uploaded the image files, but they are not showing up in my article" --and then it turns out that they forgot to press the "Start upload" button .... and it happens MOST of the time. It's as if people's IQ drops by 20% when they are on internet. So, this auto-upload is really a critical functionality. The question is how to get it to work in plupload?
Comment #20
drupalina CreditAttribution: drupalina commented[drupal.org repeated the same comment above]
Comment #21
drupalina CreditAttribution: drupalina commented[drupal.org repeated the same comment above]
Comment #22
mohit_aghera CreditAttribution: mohit_aghera commented@drupalina,
I got your point, actually i also faced this kind of situation, but none of the above solutions worked for me.
Are you using CCK in your form or created form programmatically..
I was using plupload in custom form i.e. form created programmatically rather than CCK forms
What i did was to disable ""Start upload" button and manage the file upload in form submit handler. When I submit the form I managed uploading files manually.
Comment #23
drupalina CreditAttribution: drupalina commented@mohit_rocks (sorry for the duplicate posts. Drupal.org is misbehaving)
Yes, my image field is done through CCK (built into D7). Do you know how to achieve this Auto-upload functionality for CCK plupload fields? Thanks.
Comment #24
vladan.me CreditAttribution: vladan.me commentedI believe this would work, althought not configurable, just as a temporary solution... Can you please try it so I can try making it better?
----------------
Edit: Paths in patch might not be configured right, sorry
Comment #25
vladan.me CreditAttribution: vladan.me commentedSecond try
Comment #26
vladan.me CreditAttribution: vladan.me commentedi've got something, just not sure if is "pretty" solution. Please revise...
This would make images autoupload and autosubmit form that you pass (through form id).
I am making assumption that images are processed in some custom form?
Usage would be something like:
Comment #27
drupalina CreditAttribution: drupalina commentedI manually applied the patch in #26 ,cleared the cache. Nothing changed- we still need to click the "Start upload" button.
I didn't apply the $options code because I didn't know where to put it ???
Comment #28
vladan.me CreditAttribution: vladan.me commentedIn place where you define your plupload as a type - as in first post of this issue, for example
You just need to enter exact id of your form which will process images uploaded... Maybe there's more obvious way to do it but I am not aware of it right now.
Comment #29
drupalina CreditAttribution: drupalina commentedOK - thanks. But I'm not a coder.
Please tell me:
1) in which file should I add this "$options['plupload_settings'] = array(" code? is it plupload.module ? or some kind of .inc file? and on which line?
2) what do I need to put instead of "gallery_upload" and "#my-form-upload-id" ??? How do I find out what these variables are on my own installation?
Thanks!
Comment #30
vladan.me CreditAttribution: vladan.me commented@drupalina
Are you sure you are using this module and not https://drupal.org/project/plup ?
Sorry to ask that question but I am kind of confused with your questions and I read at plup module:
" It provides a field widget for image field that allow user to upload multiple images at once using Plupload library."
I am not aware that this module is able to integrate as field widget for image field, or I am missing something big?
Comment #31
drupalina CreditAttribution: drupalina commented@vladan.me yes, my Plup module is disabled. And yes you are missing something :) because you can use this Plupload integration module to upload multiple images . Watch this screencast http://youtu.be/lKfDIWdWQ5c
Now back to my 2 questions in #29 :
1) in which file should I add this "$options['plupload_settings'] = array(" code? is it plupload.module ? or some kind of .inc file? and on which line?
2) what do I need to put instead of "gallery_upload" and "#my-form-upload-id" ??? How do I find out what these variables are on my own installation?
Comment #32
vladan.me CreditAttribution: vladan.me commentedAh, ok, I see... I have checked those modules and found out that they are using their custom version of plupload... Pretty much independent from this since it's overwriting plupload.js. What I am trying to say, that patch I wrote for this module doesn't affect your case.
Anyway, you should better contact maintainer of filefield_sources_plupload to see if he can help you with it.
Cheers
Comment #33
drupalina CreditAttribution: drupalina commentedThanks @vladan.me - I will definitely take this up with filefield_source_upload .
Comment #34
vladan.me CreditAttribution: vladan.me commentedCan maintainer please review patch submitted in #26? Thanks
Comment #35
slashrsm CreditAttribution: slashrsm commentedIt looks nice. I'd just like to see some info about this in README.txt. People will not know about this new feature if we don't document it.
Comment #36
slashrsm CreditAttribution: slashrsm commentedHere is my proposal:
1. Some docs added to README.txt.
2. I think that we should make automatic submit optional. Added another setting that handles this.
3. Auto-submit should check if there is #submit_element and use that specific element to submit if it does.
4. No need to add form ID, since the form element can be found in JS.
Comment #37
vladan.me CreditAttribution: vladan.me commentedThere are two problems here that may occur:
1) if you want to use autosubmit without autoupload by default you won't get uploaded images. You will have to make custom callback to upload images.
2) If you want to use autoupload without autosubmit by default you will have "locked" plupload form without being able to click add or start again since after upload it will overwrite it with "Uploaded" text. Again, you will have to make custom callback to submit images.
Comment #38
slashrsm CreditAttribution: slashrsm commentedMy idea was to only support autosubmit together with autoupload. #36 should work that way.
Submit is done via Drupal native form and PLupload should not interfere with that by default. I way playing with this on File entity upload form and it worked OK (i.e. autoupload uploaded files and I normally submitted form by pressing "Next" when it was done).
Comment #39
vladan.me CreditAttribution: vladan.me commentedYes, that is true, I am just pointing out that if this option is enabled you will not be able to upload more files with plupload in that form, but ok, that is on user to decide if he wants this option.
Comment #40
slashrsm CreditAttribution: slashrsm commentedThat's true. Maybe we should express that in README.txt docs once patch is ready.
I'll close this as we're effectively going to do most of coding in #2065927: Plupload events support?.
Comment #41
NWOM CreditAttribution: NWOM commentedFor those using FileField Sources Plupload, there is a JS file that can be added to your theme to make this possible: #2101363: Automatic upload for Plupload files
Comment #42
NWOM CreditAttribution: NWOM commented