Inserting a new input field

How can I insert another field? I want to add a new field called keywords. anyway of doing this?

gyphie's picture

Post params

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.

Example...

Can you give a code example?

BUMP

BUMP

gyphie's picture

Sleeping at 4am

<form>
<input type="text" id="mytextbox" value="this is the value" />
</form>

--------

function uploadStartHandler(file) {
this.addFileParam(file.id, "myvaluetopost" document.getElementById("mytextbox").value);

}

Which file do I modify?

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?

bump

bump

Yes

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

When I modified the

When I modified the handlers.js file the flash went away and the regular upload input replaced the flash. Any other ideas?

Some more help passing values

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 ) );

Flash went away due to js errors

What errors did you get when you added the code in?

moreValues?

when you say put moreValues in the getElemenetById what values go here? I have not messed with JS in a long time

ID of element

Sorry my example was a little wrong. moreValues = id of the input element you want

e.g.

< input id="moreValues" .....

ok got that, but...

My script begins uploading automatically, anyway to fix this?

bump

bump

I got problems with this too

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.

BUMP

BUMP

close's picture

Worked for me

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.

It doesn't seem that

..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...

I got it!

Seems it was my php-code that was screwed.. Not easy to debug sending mails Smiling
Regards!