In my page I add extra 3 new fields (name, phone, email) when clicking on "Add more fields". I want to add all value of 3 field to an array and send them to view.py without using ajax.
Example: I click on add more fields 2 times and I want add all them to an array allow pair value like this: [{'MrA','mra@gmail.com'},{'MrB','mrb@gmail.com'}]
. But in view.py I'm using command request.POST.get('name') and request.POST.get('email')
it just get only one pair value last input.
How to get each pair value in that array?
HTML
<form action="'{% url 'add_more_field' %}'" method="post">
<ul id="fieldList">
<li>
<input name="name" type="text" placeholder="Name" />
</li>
<li>
<input name="email" type="text" placeholder="E-Mail">
</li>
</ul>
<button id="addMore">Add more fields</button>
<br>
<br>
<input type="submit">
</form>
JS
$(function() {
$("#addMore").click(function(e) {
e.preventDefault();
$("#fieldList").append("<li> </li>");
$("#fieldList").append("<li><input type='text' name='name' placeholder='Name' /></li>");
$("#fieldList").append("<li><input type='text' name='email' placeholder='E-Mail' /></li>");
});
});
view.py
def add_more_field(request):
person = Person()
if request.method == 'POST':
name = request.POST.get('name')
email = request.POST.get('email')
return render(request, 'index.html')