Welcome Guest, Not a member yet? Register   Sign In
What about elements added by jquery?
#1

[eluser]macron[/eluser]
Hi
I'm doing this
Code:
->iupload('img','Add image',FALSE,array('class' => 'image'))

and in a js file I'm binding a clickevent to an ancor that injects another input type file so I can add several images via the form
Code:
$(function(){
    $('a.button').bind('click', function(event){
        // add image label and input
        $('<label for="img" class="left">&nbsp;</label>&lt;input type="file" name="img" value="" id="img" class="image"  /&gt;&lt;br />').insertBefore('#last');

        // loop through all input[file] and rename to img1, img2, img3 ...
        $("input.image").attr("name", function (arr) {
          return "img" + arr;
        })
        ;
    });
});

As you can see I'm renaming the input to img1, img2, img3 ... but I never get access to these via
Code:
$this->form->get_post(TRUE);

I only get access to the org img and that one is set to false. That part I do understand as no element is now just name img but img1, img2...

What am I doing wrong here?

Fantastic lib though. Saves me a huge amount of time
#2

[eluser]teampoop[/eluser]
So special note about the name attribute.. it's read only once it's placed in the DOM. So you may be actioning it to change the name to img1, img2, etc, but it's actually only sending img.. Use Firebug to see the post headers when you send your form to verify that.

possible solutions: attach the number when you create the image

Code:
$(function(){
    $('a.button').bind('click', function(event){
        len = $("input.image").length + 1;
        // add image label and input
        $('<label for="img" class="left">&nbsp;</label>&lt;input type="file" name="img'+ len + '" value="" id="img" class="image"  /&gt;&lt;br />').insertBefore('#last');
    });
});
#3

[eluser]vitoco[/eluser]
what you need it's the .live() method, this one add events to the elements created in the first load and also to the the elements created on the fly.

http://api.jquery.com/live/

Saludos
#4

[eluser]macron[/eluser]
Hi teampoop
OK, changing the jquery bind and add function as you proposed made it clear that I do get all input type file posted to my server. I see the files in $_FILES but I'm not seeing them in the returned $data array from the upload lib. I only see the image that I created prior to sending the form to the view.

I'm using Frank Michels FormLib (http://www.frankmichel.com/formgenlib/us...index.html). But that one is based on CI own upload lib and I suspect (will test this later today) the problem lies within the CI lib




Theme © iAndrew 2016 - Forum software by © MyBB