I have an HTML Form that contains groups of similar items. I know HTML has no concept of “arrays” so I’m wondering what is the best way to write something that contains a single form and can have multiple groups of the same items added as needed.
<form>
<div>
<input name="title[]">
<textarea name="body[]">
</div>
<div>
<input name="title[]">
<textarea name="body[]">
</div>
<a href="#" id="addrow">Add row</a>
<input type="submit">
</form>
You could have something like this:
When you add div with javascript/php or whatever, just add count of elements in hidden input num_of_elements
and then when you submit it in PHP you would have variables like: