jQuery-File-Upload icon indicating copy to clipboard operation
jQuery-File-Upload copied to clipboard

formData not working server side

Open kraigballa opened this issue 13 years ago • 1 comments

I am trying to send additional form data like how you describe in https://github.com/blueimp/jQuery-File-Upload/wiki/How-to-submit-additional-form-data however it doesn't seem to be working. I get an error even though it does upload. "SyntaxError: Unexpected token <" Below is what I'm doing:

The Form:

<script id="template-upload" type="text/x-tmpl">
 {% for (var i=0, file; file=o.files[i]; i++) { %}
  <tr class="template-upload fade">
    <td colspan="2" class="preview"><span class="fade"></span></td>
    <td class="title"><label>Title: <input name="title" required></label></td>

main.js:

$('#fileupload').bind('fileuploadsubmit', function (e, data) {
    var inputs = data.context.find(':input');
    if (inputs.filter('[required][value=""]').first().focus().length) {
        return false;
    }
    data.formData = inputs.serializeArray();
    console.log(inputs.serializeArray());
});

UploadHandler.php - I tried here first because your comment says Handle form data

protected function handle_form_data($file, $index) {
    // Handle form data, e.g. $_REQUEST['description'][$index]
    $file->userID = $_REQUEST['title'][$index];  // I've tried $_POST['title'][$index] too
    return $file;
}

UploadHandler.php I've tried to put it in the post function as well and removing the above code...then adding a $title parameter to handle_file_upload, but POST is still not collecting any values

public function post($print_response = true) {
        .....
        $files[] = $this->handle_file_upload(
            isset($upload['tmp_name']) ? $upload['tmp_name'] : null,
            $file_name ? $file_name : (isset($upload['name']) ?
                    $upload['name'] : null),
            $size ? $size : (isset($upload['size']) ?
                    $upload['size'] : $_SERVER['CONTENT_LENGTH']),
            isset($upload['type']) ?
                    $upload['type'] : $_SERVER['CONTENT_TYPE'],
            isset($upload['error']) ? $upload['error'] : null,
            null,
            $content_range,
            isset($_POST['title']) && $_POST['title']
        );

My console output: Screen Shot 2012-12-13 at 11 50 40 PM

As you can see the formData is being populated, but when I try and retrieve it on the server side whether I use REQUEST or POST the form data is blank. Am I doing the right thing in UploadHandler.php?

kraigballa avatar Dec 13 '12 22:12 kraigballa

Please post support requests and general discussions about this project to the support forum: https://groups.google.com/d/forum/jquery-fileupload

The issues tracker should only be used for bugs or feature requests: https://github.com/blueimp/jQuery-File-Upload/blob/master/CONTRIBUTING.md

blueimp avatar Dec 14 '12 11:12 blueimp