I use a script for form validation (validationEngine) and a script for file upload (uploadify).
To best manage my form submission:
- validationEngine detects if my form can be sent.
- If I can submit, I upload my files
- Once all my uploaded files (
onQueueComplete
uploadify), I submit my form.
If I make an alert('foo');
in my onQueueComplete, it works. But if I submit my selector.submit()
... nothing happens.
$(function() {
$('#file_upload').uploadify({
'fileSizeLimit' : '2048KB',
'auto': false,
'swf' : '<?php echo site_url('public/modules/uploadify/uploadify.swf')?>',
'uploader' : '<?php echo site_url('public/modules/uploadify/uploadify.php')?>',
'buttonText' : 'Ajouter...',
'method' : 'post',
'formData' : {'userMail' : '<?php echo $userMail ?>'},
'onQueueComplete' : function(queueData) {
$('#validator').submit();
}
});
});
$(document).ready(function() {
$("#validator").validationEngine();
$('#validator').submit(function(event){
event.preventDefault();
var canSubmit = $("#validator").validationEngine('validate');
if(canSubmit)
{
$('#file_upload').uploadify('upload','*');
}
});
});
With this code, all works but submit doesn't work. It's like the event doesn't exist.
Should it not be:
This method complicates the task myself. I decided to do a new routine easier.
I let the file load automatically. And I just created elements that I delete.
Anyway, to send my mail, file attachments will be destroyed.
here is my new code and it works.
Two things:
(1) Your selector elsewhere is
#validator
, whereas you are usingvalidator
in the non-functional call.(2) You are
preventDefault
ing everysubmit
event that originates on#validator
, so even if the event was correctly triggered it would not execute a submit action. You need to call the native DOM element'ssubmit
action instead:[0]
gets the native DOM element from the selection, and you then call the nativesubmit
function. This means no jQuery handlers are run, so theevent.preventDefault
call you make is also not run, so the event will function.