Answer the question
In order to leave comments, you need to log in
How to correctly implement the form of adding n-copies of the same model (inputs) in one form without reloading?
Good day.
There is a form for creating an indefinite number of products.
Model - Product.
How to properly compose this form so that you can create an unlimited number of products (array)?
If I need to duplicate a field, then I do this:
<input type="text" name="Product[field_name][]">
<input type="text" name="Product[field_name][]">
<input type="text" name="Product[][name]">
<input type="text" name="Product[][description]">
<!-- Первый продукт, запишется с ключом 0 -->
<form-item>
<input type="text" name="Product[][name]">
<input type="text" name="Product[][description]">
</form-item>
<!-- Второй продукт, запишется с ключом 1 -->
<form-item>
<input type="text" name="Product[][name]">
<input type="text" name="Product[][description]">
</form-item>
<input type="text" name="Product[<?=$productModel->id;?>][name]">
<input type="text" name="Product[<?=$productModel->id;?>][description]">
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question