plupload submit routine is not called I'm having a problem with the plupload module.
The normal upload works perfect, the files are stored in sites\default\files\tmp.
I'd like to "walk" through the uploaded files using the hook_submit.
It seems, this hook is not called, when pressing start upload on the plupload form.
I'm using almost the same hook_submit as the test form in the plupload.module.

What am I doing wrong?

Here is my form definition:

 $form['my_element'] = array(
'#type' =&gt; 'plupload',
'#title' =&gt; t('Upload files'),
'#description' =&gt; t('This multi-upload widget uses Plupload library.'),
'#upload_validators' =&gt; array(
  'file_validate_extensions' =&gt; array('jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp'),
  'my_custom_file_validator' =&gt; array('some validation criteria'),
),
'#plupload_settings' =&gt; array(
  'runtimes' =&gt; 'flash,html4',
  'url' =&gt; url('plupload-handle-uploads', array('query' =&gt; array('plupload_token' =&gt; drupal_get_token('plupload-handle-uploads')))),
  'max_file_size' =&gt; file_upload_max_size() . 'b',
  'chunk_size' =&gt; '1mb',
  'unique_names' =&gt; TRUE,
  'flash_swf_url' =&gt; file_create_url('sites/all/libraries/plupload/js/plupload.flash.swf'),
  'silverlight_xap_url' =&gt; file_create_url('sites/all/libraries/plupload/js/plupload.silverlight.xap')
),
);


Here is the submit function:

function get_upload_form_submit($form_id, &amp;$form_state) {
//handle file uploading
global $user;

$saved_files = array(); //Array to capture file objects
$scheme = variable_get('file_default_scheme', 'public') . '://';
$directoryname = 'imagebank'; // Directory where images are collected
$imagebankpath = $scheme . $directoryname;
dpm($imagebankpath);
file_prepare_directory($imagebankpath, FILE_CREATE_DIRECTORY); // Create the folder if   it doesn't exist
// We can't use file_save_upload() because of
// http://www.jacobsingh.name/content/tight-coupling-no-not
// file_uri_to_object();
foreach ($form_state['values']['uploadfiles'] as $uploaded_file) {
if ($uploaded_file['status'] == 'done') {
  $source = $uploaded_file['tmppath'];
  $destination = file_stream_wrapper_uri_normalize($imagebankpath .'/'. $uploaded_file['name']);
  // Rename it to its original name, and put it in its final home.
  // Note - not using file_move here because if we call file_get_mime
  // (in file_uri_to_object) while it has a .tmp extension, it horks.
  $destination = file_unmanaged_move($source, $destination, FILE_EXISTS_RENAME);
  $file = plupload_file_uri_to_object($destination);
  file_save($file);
  $saved_files[] = $file;
}
else {
  form_set_error('uploadfiles', "Upload of {$uploaded_file['name']} failed");
}
}
}


Did I forgot anything?
Thx.
The submit handler is not executed when clicking on the start upload of the Plupload widget form, this only executes the ajax upload of the files (and the file validators).

To have a submit callback, and handle the logic of the uploaded files (i.e.: move files to a certain directory), you should add a button to the form.

$form['submit'] = array(
    '#type' =&gt; 'submit',
    '#value' =&gt; t('Submit'),
    '#submit' =&gt; array('get_upload_form_submit'),
);


The uploaded files are stored in the form_state under $form_state['values']['my_element'] (the name of your Plupload form field)

Update #1

Some sample code to trigger the form submit callback once the upload of the files is finished by the Plupload uploader. Basically what you need:


A submit button attached to the form to have a submit callback (which handles the uploaded files)
A custom javascript which intercepts the UploadComplete event triggered by the Plupload component
On the UploadComplete interception, trigger a click on the submit button




function YOURMODULE_form($form, &amp;$form_state)
{
    // your form elements with plupload form element

    // add a submit button
    $form['submit'] = array(
        '#type' =&gt; 'submit',
        '#value' =&gt; t('Save file(s)'),
        '#submit' =&gt; array('YOURMODULE_form_submit'),
        '#attributes' =&gt; array(
            'class' =&gt; array('file-upload-submit'),
        ),
    );

    // attach the custom js to the form
    $form['#attached'] = array(
        'js' =&gt; array(
            drupal_get_path('module', 'YOURMODULE') . '/js/YOURMODULE.js',
        ),
    );

    return $form
}

function YOURMODULE_form_submit($form, &amp;$form_state)
{
    // put uploaded files in a 'uploads' directory
    $directory = sprintf('%s://%s',
        variable_get('file_default_scheme', 'public'), 'uploads');

    // be sure directory exists (and create it)
    file_prepare_directory($directory, FILE_CREATE_DIRECTORY);

    // loop through each uploaded file
    $saved_files = array();
    foreach ($form_state['values']['files'] as $file) {
        if ($file['status'] !== 'done') {
            //handle error on upload fail
            continue;
        }

        // move files from tmp directory to defined directory
        $destination = file_unmanaged_move(
            $file['tmppath'], 
            file_stream_wrapper_uri_normalize($directory . '/' . $file['name']), 
            FILE_EXISTS_RENAME
        );

        $saved_file = plupload_file_uri_to_object($destination);
        file_save($saved_file);

        $saved_files[] = $saved_file;
    }

    // keep saved files in form state to be able to stuff afterwards (if needed)
    $form_state['saved_files'] = $saved_files;

    drupal_set_message(t('Files have been uploaded and saved.'));
}


The javascript (under js/YOURMODULE.js)

(function ($) {
    Drupal.behaviors.YOURMODULE = {
        context: null,
        attach: function (context) {
            var that = this,
                uploader = $('.plupload-element', context).pluploadQueue();

            this.context = context;

            if (!uploader) {
                return false;
            }

            uploader.bind('FilesAdded', function() {
                // start upload automatically once files have been added to queue
                that.start();
            });

            uploader.bind('UploadComplete', function() {
                // trigger click on submit button to submit form once upload completed
                that.complete();
            });

            return this;
        },
        start: function() {
            $('.file-upload-submit', this.context)
                .attr('disabled', 'disabled');
        },
        complete: function() {
            $('.file-upload-submit', this.context)
                .removeAttr('disabled')
                .click();
        }
    };

})(jQuery);