Search code examples
htmlpostrelated-content

How to POST relational data with html form


I have a dynamic html form that creates with javascript new inputs for some products and each product has more colors.

<input type="text name="products[]">
<input type="text name="colors[]">

How do i create this html code so that when i have them in the post i could relate them with a for.


Solution

  • do it like this:

    <input type="text name="products[product_index][name]">
    <input type="text name="products[product_index][colors][]">
    

    or :

    <input type="text name="products[product_index]">
    <input type="text name="[colors][product_index][]">