The problem is this. It is necessary to add several data of the same type through the form (the number is not known in advance). Data has several properties. For example, "expenses": type, name, amount. Made a form with a table with input fields (input, select). The field names are set as follows.

<input type="text" name="charges[new][sum]"> <input type="text" name="charges[new][description]> 

Data is handled by php (as an array). I wanted to send several expenses at a time. I took a string with an input field and cloned it with jquery.
Is it possible to somehow easily change the index of the input fields ("new" change to "new2" or "new3", for example)?

  • after cloning nothing prevents to go and change the necessary attribute - Grundy
  • Yes, this is understandable. This, in addition to selecting the fields themselves, also needs to be changed in the attribute value. Maybe that is easier to eat? - ArchDemon
  • Before sending to the server from all inputs with the same name, you can collect an array and send as one field. In such an implementation, the server does not need to think how many fields new1,2 will be, n just iterate over an array of a previously known field - sivik_xes
  • @sivik_xes, I refused this decision. Problems with checkbox, not wanting jquery to be here too - ArchDemon
  • Well, this is still an option, maybe not very good, but create input type hidden c name - charges [new] [sum] and collect all of this text input from all text inputs, it turns out that sending will be without jquery, but the array will come to the server as you need - sivik_xes

0