<<< Back to the TFU FAQ

TFU flash upload faq image 15. How to send form fields with the upload - professional license or above

Since TFU 2.10 it is possible to that TFU reads form fields from the html page and adds then to the upload as 'get' parameters. To enable this you have to do the following:

Add input fileds to your page where the flash is included e.g.

<input id="tfu_field" type="textfield" />
<select id="tfu_select">
   <option value="en">English</option>
   <option value="de">German</option>
</select>

each elements need a unique id because this is needed in the configuration!

Then you have to insert the following Javascript to your page:

<script type="text/javascript">
function getTFUFormData(fields) {
var validateOk = true;
var spacer = String.fromCharCode(4);
// You have to return doNotUpload if you e.g. have mandatory fields and they are not filed.
// add the check to this function and return 'doNotUpload'. Then the upload is not started.
// noone should enter this
var doNotUpload = String.fromCharCode(5) + String.fromCharCode(4) + String.fromCharCode(5);

var result="";
var sarray = fields.split(",");
for (var i = 0; i < sarray.length; ++i) {
if (document.getElementById(sarray[i])) {
result += document.getElementById(sarray[i]).value;
}
result += spacer;
}
// if you validate and the validation fails return doNotUpload to prevent the upload
if (validateOk) {
return result;
} else {
return doNotUpload;
}
}
</script>

This Javascript does not to any validation of your input fields yet. You have to add this by yourself! This function does already exist in tfu.htm.

And finally you have to add all id's of the input fields as comma seperated list to the tfu_config.php:

$form_fields = 'tfu_field,tfu_select';

Currently this setting is not available in JFU directly. You have to do the setup like described here.

If you now upload a file the specified fields are sent as 'get' parameters with the upload. You can now easily read them in tfu_upload.php with e.g.

$tfu_select = $_GET['tfu_select'];

you can use the tfu function parseInputParameter to secure the input. It olny allows allows digits, word characters, whitespaces, '_' , ',' and ' '-'. e.g.

$tfu_select = parseInputParameter($_GET['tfu_select']);

The best way to read the parameters is to use a plugin. On the plugin page you can use the log plugin as base and extend it to your needs.

esta-registration.co.uk