1

I've created a form that targets an iframe to submit an image. I absolutely had this working previously, but now the whole page submits, instead of just the iframe. I'm at a total loss.

HTML:

<form id="upload-form" name="upload-form" class="" action="/handle/upload" method="post" enctype="multipart/form-data">
    <div class="fileinput-wrap">
        <label for="fileinput">Image input</label>
        <input type="file" name="file" id="fileinput" />
     </div>
    <input type="submit" id="submitter" name="submitter" />
</form>

JS:

$("#fileinput").on('change', function () {
    var $iframe = $("<iframe />").attr({
        id: 'frame_uploader',
        name: 'frame_uploader'
    });
    var $img = $("<img />");
    var imageUrl = "";
    $("#upload-form").prepend($img).append($iframe)
        .attr('target', 'frame_uploader')
        .trigger('submit');
    $iframe.load(function () {
        var imageUrl = $iframe.contents().find("body").text();
        $img.attr('src', imageUrl);
    });
});

http://jsfiddle.net/NVp9K/

Christopher Meyers
  • 329
  • 1
  • 3
  • 15

2 Answers2

1

I read somewhere that certain iframe names are reserved. Changing the name of the iframe has fixed the problem.

Christopher Meyers
  • 329
  • 1
  • 3
  • 15
  • Thank you! Thank you! Thank you! That's a real pain to debug, had the same issue with my iframe called "background_file_upload", changing it to "my_iframe" and voila! it worked. – davur Nov 05 '13 at 01:29
  • it's not working for me.. – mazend May 23 '23 at 13:32
1

Maybe you should add frame id and name attribute when it is created. Just like this:

var $iframe = $("<iframe id=\"frame_uploader\" name=\"frame_uploader\" />");