0

I have a problem, i searched for the solution all over the internet, but i couldn't find it out :S

The problem is:

I'm creating file inputs on button click, but i can't handle these javascript made inputs because they aren't in my $_FILES array after i click on submit..

My code is:

HTML:

<form name = "galleryupload_form" method = "post" action = "#" enctype="multipart/form-data">
    <ul id = "formul">      
    </ul>
    <input type="button" value="Még egy kép feltöltése" onClick="addInput('formul');">
    <input name = "galleryupload_submit" type = "submit" value = "Küldés"/>
</form>

javascript:

var counter = 0;
var limit = 5;

function addInput(ulName) {
    if (counter == limit) {
        alert("You have reached the limit of adding " + counter + " inputs");
    } else {
        var newli = document.createElement('div');
        newli.innerHTML = "<label for = ''>Fájl " + (counter + 1) + "</label><input type='file' name='files[]'>";
        document.getElementById(ulName).appendChild(newli);
        counter++;
    }
}

If you now the solution, please let me know. Thank you.

Flashcap20
  • 105
  • 1
  • 7
  • `newli` should be an `li`, not a `div`. http://stackoverflow.com/questions/11755628/can-i-use-div-as-a-direct-child-of-ul – Barmar Dec 24 '13 at 11:58
  • If you are going to have a `for` attribute in your label, then give it the id of the field it is for. If you aren't, put that field inside the label. – Quentin Dec 24 '13 at 12:01

2 Answers2

3

Referring to the question before editing:

File inputs appear in $_FILES not $_POST.


After editing, I cannot reproduce the problem.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
-1

check this code .

<?php 
if(isset($_POST['galleryupload_submit'])){
 print_r($_FILES);
}
?>
<form name = "galleryupload_form" method = "post" action = "" enctype="multipart/form-data">
    <ul id = "formul">      
    </ul>
    <input type="button" value="My textbox goes" onClick="addInput('formul');">
    <input name ="galleryupload_submit" type ="submit" value ="Click Add"/>
</form>
<script>

  var counter = 0;
  var limit = 5;
        function addInput(ulName){
               if (counter == limit)  {
                alert("You have reached the limit of adding " + counter + " inputs");
            }else {
                var newli = document.createElement('div');
                newli.innerHTML = "<label for = ''>New TexBOx " + (counter + 1) +"</label><input type='file' name='files[]'>";
                    document.getElementById(ulName).appendChild(newli);
                counter++;
            }
}
</script>
Mahmood Rehman
  • 4,303
  • 7
  • 39
  • 76