0

I want to create a form that insert multiple entries to a table, i don't know how to pass the data to the post or make an array in order to have de data available. Everytime the user click the boton I append to the form 3 inputs that i need for that entry.

<button class="btn btn-default" onclick="addPrice()">Add</button>
<div>
    <form class='form-inline range' id="range" method='post' action='/providers/range_price'></form>
</div>

Javascript:

function addPrice(){
var add = $('.range').append("<div class='row'><div class='col-md-12'><div class='form-group'><label class='linput' for='prices'> Price</label><input type='text' class='form-control' id='prices' name='prices' placeholder='Price'></div><div class='form-group'><label class='linput' for='minP'> Min</label><input type='number' class='form-control' id='minP' name='min' placeholder='Min'></div><div class='form-group'><label class='linput' for='maxP'> Max</label><input type='number' class='form-control' id='maxP' name="max" placeholder='Max'></div> </div></div><hr>"); 
} 
cssyphus
  • 37,875
  • 18
  • 96
  • 111
  • So what's the issue? What isn't working? – aphextwix Apr 06 '16 at 18:20
  • 2
    For starters, this is going to result in invalid HTML because you're going to be re-using `id` values. You also need to give your form elements `name` attributes in order for them to send anything to the server. – David Apr 06 '16 at 18:23
  • You are also forgetting to `name` your inputs. What do you have on the server side? In PHP, for instance, you can do `` several times which will produce an array on the server side (in `$_POST['foo']`). – Kenney Apr 06 '16 at 18:25
  • @aphextwix I dont know how to pass the info to the server via POST. – Ana Gonzalez Apr 06 '16 at 18:36
  • @Kenney I am using nodejs, but the problem I have is that I dont know how to make an array with all that inputs. – Ana Gonzalez Apr 06 '16 at 18:39
  • 1
    Are you using Express? If so, have a look at [this question](http://stackoverflow.com/questions/4295782/how-do-you-extract-post-data-in-node-js) and [this question](http://stackoverflow.com/questions/5710358/how-to-retrieve-post-query-parameters-in-express). – Kenney Apr 06 '16 at 18:42

0 Answers0