how to retrieve dynamically created fields' (in templates) values in django views.py

35 views Asked by At

i have created multiple dynamically form field in the .html file within the templates/app_name folder using javascript. I want to retrieve the values of those dynamically created fields in views.py in django.

My javascript(addInput.js)

var counter = 1;
var limit = 5;
function addInput(divName){

        if(counter == limit){

            alert("You have reached the limit of adding " + counter + " Email Addresses");

        }
        else {

                var newdiv = document.createElement('div');
                newdiv.innerHTML = "<p id = 'remove" + counter + "'>Email Address " + (counter+1) + " : " + "<input id = 'myId" + (counter+1 + "' type = 'text' name ='myInputs[]'></p>";
                document.getElementById(divName).appendChild(newdiv);
                counter++;
                alert(counter + "add");
        }
   }

My .html(in templates/app_name folder)

<form method="POST" onsubmit = "return validateEmail('dynamicInput');" action = "/fcui/register/">
    <div id = "dynamicInput">
        <p id = 'remove0'>Email Address 1 : <input id = "myId1" type="text" name="myInputs[]"></p>        
    </div>
    <br><br><input type ="button" value= "Add another Email Address" onClick = "addInput('dynamicInput');">
        <input type ="button" value= "Remove Email Address Field " onClick = "removeInput('dynamicInput');">

        <br><br><input type ="submit" value= "Send Invites" > 
        <input type='hidden' name='csrfmiddlewaretoken' value='xyz' />
</form>

I have tried retrieving it as :

   print request.POST['myInputs[]']

but it retrieves only one value i.e. last field value

How can I retrieve all other values? I tried searching this on Internet but did not find relevant in django context. Please Help. I am new to django.

0

There are 0 answers