To send additional data with an upload you can either use the post_params setting and functions or the addFileParam functions.
post_params are sent with all uploads. addPostParam and setPostParams allow you to update these values.
addFileParam adds a name/value pair to be sent with a specified file.
These functions are described in the documentation.
One thing to remember is that once you set a post_param that it is not magically updated if you update the input element that you got its value from. You need to update the post params/file params immediately before the file is uploaded if you want to be sure you've got the latest value. The uploadStart event is a good place to do this.
noosemonsewicz Says:
April 9, 2008 - 7:49am
Can you give a code example?
noosemonsewicz Says:
April 9, 2008 - 10:25am
BUMP
gyphie Says:
April 9, 2008 - 12:25pm
<form>
<input type="text" id="mytextbox" value="this is the value" />
</form>
--------
function uploadStartHandler(file) {
this.addFileParam(file.id, "myvaluetopost" document.getElementById("mytextbox").value);
}
noosemonsewicz Says:
April 9, 2008 - 12:56pm
Which file do I modify to place this code into?
The above snippet of code, handles the startUpload() function. Would I place your bit of code inside the startUpload function inside the handlers.js file?
noosemonsewicz Says:
April 10, 2008 - 2:36pm
bump
msteudel Says:
April 10, 2008 - 3:27pm
Just trying to help here so I may be wrong:
// add into where you initialize your swfupload object
upload_start_handler : uploadStart, <-- this might be your startUpload function, or you could modify the uploadStar function
Either add in your startUpload function to the handler.js or modify the uploadStart() function in the handlers.js
noosemonsewicz Says:
April 10, 2008 - 3:33pm
When I modified the handlers.js file the flash went away and the regular upload input replaced the flash. Any other ideas?
msteudel Says:
April 10, 2008 - 3:42pm
Ok I tried this out and got this working. Maybe this will help:
[form.html]
// You hav ethe following field on your form page with the uploader
< input type="text" name="moreValues" />
// STEP 1:
// Make sure to add additional post parameters where you initialize your swfupload object ( we are still in your form.html)
post_params: {"PHPSESSID" : "<?php echo session_id(); ?>", "moreValues" : "" },
[handlers.js]
//STEP 2:
// Edit your uploadStart() function and add the following line into your try block
this.addFileParam(fileObj.id, "firstName", document.getElementById("moreValues").value);
[upload.php]
// STEP 3:
// mail yourself your post values to see if it's working
mail( 'email@email.com', 'SWFUpload Values', print_r( $_POST, true ) );
msteudel Says:
April 10, 2008 - 3:42pm
What errors did you get when you added the code in?
noosemonsewicz Says:
April 10, 2008 - 3:55pm
when you say put moreValues in the getElemenetById what values go here? I have not messed with JS in a long time
msteudel Says:
April 10, 2008 - 3:58pm
Sorry my example was a little wrong. moreValues = id of the input element you want
e.g.
< input id="moreValues" .....
noosemonsewicz Says:
April 10, 2008 - 4:04pm
My script begins uploading automatically, anyway to fix this?
noosemonsewicz Says:
April 11, 2008 - 8:13am
bump
myVR Says:
April 14, 2008 - 5:47am
Should I use swfupload_f8.swf or swfupload_f9.swf?
Output of the mail sent to me is:
Array
(
[Filename] => test.myvr
[Upload] => Submit Query
)
I should have modelTitle and modelDesc too..
---
I added these lines to my handles.js file:
this.addFileParam(fileObj.id, "modelTitle", document.getElementById('modelTitle').value);
this.addFileParam(fileObj.id, "modelDesc", document.getElementById('modelDesc').value);
And I got textfields in my main-file id'ed with id="modelTitle" and id="modelDesc"
Thanks.
noosemonsewicz Says:
April 15, 2008 - 1:13pm
BUMP
close Says:
April 20, 2008 - 7:47pm
The example by msteudel worked for me with swfupload_f9.swf, not with swfupload_f8.swf. Use step 1 OR step 2, depending from what you want.
myVR Says:
April 22, 2008 - 3:44am
..my swfupload_f9.swf calls the upload.php file at all..
I've put the mail(); method on top in the upload.php file, and I don't get any mail at all.
Further I've tried to change the path to the upload.php file within the creation of the swfupload object, and I don't get any errors at all.
Seems to me that the _f9.swf-file is bugged in some way...
myVR Says:
April 22, 2008 - 4:55am
Seems it was my php-code that was screwed.. Not easy to debug sending mails
Regards!
April 8, 2008 - 4:26pm
To send additional data with an upload you can either use the post_params setting and functions or the addFileParam functions.
post_params are sent with all uploads. addPostParam and setPostParams allow you to update these values.
addFileParam adds a name/value pair to be sent with a specified file.
These functions are described in the documentation.
One thing to remember is that once you set a post_param that it is not magically updated if you update the input element that you got its value from. You need to update the post params/file params immediately before the file is uploaded if you want to be sure you've got the latest value. The uploadStart event is a good place to do this.
April 9, 2008 - 7:49am
Can you give a code example?
April 9, 2008 - 10:25am
BUMP
April 9, 2008 - 12:25pm
<form>
<input type="text" id="mytextbox" value="this is the value" />
</form>
--------
function uploadStartHandler(file) {
this.addFileParam(file.id, "myvaluetopost" document.getElementById("mytextbox").value);
}
April 9, 2008 - 12:56pm
Which file do I modify to place this code into?
The above snippet of code, handles the startUpload() function. Would I place your bit of code inside the startUpload function inside the handlers.js file?
April 10, 2008 - 2:36pm
bump
April 10, 2008 - 3:27pm
Just trying to help here so I may be wrong:
// add into where you initialize your swfupload object
upload_start_handler : uploadStart, <-- this might be your startUpload function, or you could modify the uploadStar function
Either add in your startUpload function to the handler.js or modify the uploadStart() function in the handlers.js
April 10, 2008 - 3:33pm
When I modified the handlers.js file the flash went away and the regular upload input replaced the flash. Any other ideas?
April 10, 2008 - 3:42pm
Ok I tried this out and got this working. Maybe this will help:
[form.html]
// You hav ethe following field on your form page with the uploader
< input type="text" name="moreValues" />
// STEP 1:
// Make sure to add additional post parameters where you initialize your swfupload object ( we are still in your form.html)
post_params: {"PHPSESSID" : "<?php echo session_id(); ?>", "moreValues" : "" },
[handlers.js]
//STEP 2:
// Edit your uploadStart() function and add the following line into your try block
this.addFileParam(fileObj.id, "firstName", document.getElementById("moreValues").value);
[upload.php]
// STEP 3:
// mail yourself your post values to see if it's working
mail( 'email@email.com', 'SWFUpload Values', print_r( $_POST, true ) );
April 10, 2008 - 3:42pm
What errors did you get when you added the code in?
April 10, 2008 - 3:55pm
when you say put moreValues in the getElemenetById what values go here? I have not messed with JS in a long time
April 10, 2008 - 3:58pm
Sorry my example was a little wrong. moreValues = id of the input element you want
e.g.
< input id="moreValues" .....
April 10, 2008 - 4:04pm
My script begins uploading automatically, anyway to fix this?
April 11, 2008 - 8:13am
bump
April 14, 2008 - 5:47am
Should I use swfupload_f8.swf or swfupload_f9.swf?
Output of the mail sent to me is:
Array
(
[Filename] => test.myvr
[Upload] => Submit Query
)
I should have modelTitle and modelDesc too..
---
I added these lines to my handles.js file:
this.addFileParam(fileObj.id, "modelTitle", document.getElementById('modelTitle').value);
this.addFileParam(fileObj.id, "modelDesc", document.getElementById('modelDesc').value);
And I got textfields in my main-file id'ed with id="modelTitle" and id="modelDesc"
Thanks.
April 15, 2008 - 1:13pm
BUMP
April 20, 2008 - 7:47pm
The example by msteudel worked for me with swfupload_f9.swf, not with swfupload_f8.swf. Use step 1 OR step 2, depending from what you want.
April 22, 2008 - 3:44am
..my swfupload_f9.swf calls the upload.php file at all..
I've put the mail(); method on top in the upload.php file, and I don't get any mail at all.
Further I've tried to change the path to the upload.php file within the creation of the swfupload object, and I don't get any errors at all.
Seems to me that the _f9.swf-file is bugged in some way...
April 22, 2008 - 4:55am
Seems it was my php-code that was screwed.. Not easy to debug sending mails
Regards!