Submit form to iframe?

Go To StackoverFlow.com

0

Would anyone be able to tell me what I'm doing wrong in the following code that the form is not being submit to the iframe?

$(function() {
    $(".preview").click(function() {
        $('#sliderimage').wrap('<form action="/index/upload.php" method="post" id="imageform" target="imageupload" />');
        $('#imageform').submit();
        $('#sliderimage').unwrap();
        return false;
    });
});​


<iframe style="display: none;" name="imageupload" id="imageupload"></iframe>
<input type="file" id="sliderimage" name="sliderimage">
<input type="button" class="preview" value="Preview">
2012-04-05 02:41
by Renari
How do you know it's not being submitted to the iframe? It appears to me you're missing an enctype="multipart/form-data" on the form, also switch type for method in the form ta - rlemon 2012-04-05 03:00
What happens? Does the page refreshes? Goes to upload.php? Or nothing happens? Have you tried disabling the display:none, on iframe? See what goes to the iframe, if anything - Máthé Endre-Botond 2012-04-05 03:02
I know the form isn't being submit because upload.php reads and the iframe never contains the string run meaning it wasn't submit - Renari 2012-04-05 03:06
the iframe results are <?php echo "run";rlemon 2012-04-05 03:07


0

There are two problems I see right away, not sure if they will solve the issue or not.

You have set the 'type' to post. this attribute should be method.

as well you need to set the enctype on the form.

$(function() {
    $(".preview").click(function() {
        $('#sliderimage').wrap('<form action="/index/upload.php" method="post" id="imageform" target="imageupload" enctype="multipart/form-data" />');
        $('#imageform').submit();
        $('#sliderimage').unwrap();
        return false;
    });
});​

EDIT

The code above is a direct cut and paste from your source.... this means the 'hidden'(​) character jsfiddle pastes into your javascript is also there. remove it and you js will function. to do this simply backspace at the end of your js code once.

2012-04-05 03:03
by rlemon
Thanks, I made these changes, however it doesn't fix it - Renari 2012-04-05 03:06
see my update and http://rlemon.com/example.html working example, the mystery character strikes again - rlemon 2012-04-05 03:16
Thanks, that's strange lol - Renari 2012-04-05 03:49
Ads