1

I have a form with a set of input fields:

<form>
 <div class="row">
     <input type="text" name="product[1]">
     <input type="text" name="qty[1]"> 
 </div>
</form>

I also add new rows dynamically to the DOM with jquery's clone() function.

What is the best way to increase the index number? Or is there a better way to 'map' the product and qty fields before submitting to a PHP script?

4
  • 2
    you could just write product[] and qty[], PHP will deal your data like an array Commented Jan 20, 2015 at 10:37
  • product[] without index Commented Jan 20, 2015 at 10:37
  • @FabrizioCalderan, I tried this, but how will I be able to determine which qty value belongs to which product? Commented Jan 20, 2015 at 11:39
  • 1
    they are both arrays so e.g. product[42] is related to qty[42] (and vice-versa) Commented Jan 20, 2015 at 11:41

1 Answer 1

1

Try this:

<form>
 <div class="row">
     <input type="text" name="product[]">
     <input type="text" name="qty[]"> 
 </div>
   <div class="row">
     <input type="text" name="product[]">
     <input type="text" name="qty[]"> 
 </div>
</form>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.