I have a form I use to upload images:
<form action="uploadImage.php" method="post" enctype="multipart/form-data" id="UploadForm">
<input type="file" id="fileInput" name="ImageFile" help_token="upload_token" size=20 />
<input type="submit" id="SubmitButton" help_token="upload_token" value="Upload" />
<img id="loadGif" src="images/ajax-loader.gif" alt="load gif" />
</form>
I prepare the form with ajaxform:
var statustxt = $('#statustxt');
var submitbutton = $("#SubmitButton");
var myform = $("#UploadForm");
var galleryStatus2$ = $("#galleryStatus2");
var error_code;
$(myform).ajaxForm({ // called when the code loads
data : {dstDir : g.currentGal}, // pass in some $_POST parameters
resetForm : true,
beforeSend: function() { //before submitting the form
galleryStatus2$.empty(); // clear status from last upload
submitbutton.attr('disabled', ''); // disable upload button
$('img#loadGif').fadeIn(200); // start spinner
},
complete: function(response) { // upload complete
console.log("<br />upload complete. g.currentGal = " + g.currentGal);
galleryStatus2$.html(response.responseText); //upload status
submitbutton.removeAttr('disabled'); //enable submit button again
$('img#loadGif').fadeOut(200); // kill spinner
The problem I'm having is that I want to be able to tell the action script, uploadImage.php, which directory to upload to. I attempt to do this with the "data : {dstDir : g.gurrentGal}" line. g.currentGal holds the last folder double-clicked, i.e., the last folder opened and so now the target for any uploads. But the ajaxform code runs when the code loads initially, not when the form is submitted. So g.currentGal is whatever the variable was initialized to when the JavaScript first loads and never the last folder opened. How can I get the value of g.currrentGal at the time the form is submitted to be passed to uploadImage.php in the $_POST array?
Thanks
You need to delete the input submit, put a button instead. On button click you store the info inside a hidden input tag. Then (with jquery or other) you can submit the form, you will then obtain the parameters you setted on Php page trought the html form.
Edit: That said before submitting the form relaunch the g.storeFolder each time a folder is opened.