Is there any standard way to pass an array from a form to a server:

<form> <input name="nickname"> <input name="password"> <input name="nickname"> //генерируются скриптом <input name="password"> </form> 

The bottom line is that the names of the inputs are the same, and they are overwritten in the $ _GET array. Is it possible to create an array so that all these inputs automatically put data into a single array called nickname and password ?

  • It depends on how the input is located. At least each nickname and password can be wrapped in a span during output (they are probably output in a cycle) ...... and then just run through JS through each block, bringing everything into an array and passing this array through ajax - Aleksey Shimansky
  • @ Alexey Shimansky is possible not through ajax, but through the same form. The crux of the matter is to simplify this if it is real. Forms have some kind of built-in configuration for creating arrays, but I didn’t fully understand how to make them and whether it is possible to tweak them here. - Telion
  • 2
    In theory, if you put all the inputs with the names name = nickname [], and the passwords name = password [], then just the data arrays will come, you just have to match each name with its password - Alexey Shimansky
  • @ Alexey Shimansky, what you need! :) - Telion

1 answer 1

 <form> <input name="nickname[]" value=nickanme1> <input name="password[]" value=password1> <input name="nickname[]" value=nickanme2> <input name="password[]" value=password2> <input type="submit" value="submit"> </form> <pre><?print_r($_GET);?></pre> 

Have $ _GET

 Array ( [nickname] => Array ( [0] => nickanme1 [1] => nickanme2 ) [password] => Array ( [0] => password1 [1] => password2 ) 

)