Array form submission
I encountered a problem today. I had to save a lot of form information. After a long time, I finally found a good method to submit the data in the form to the background in the form of arrays for storage. In fact, the implementation is very simple, that is, there must be a certain standard for naming the name of the information to be submitted in the form. Let's first compare the differences between the two methods below: first, in normal mode, each value to be submitted has a name <form id = "form1" action = ". /index. php "method =" get "> <div class =" form-control "> <input type =" text "name =" name1 "/> <input type =" text "name = "num1"/> <input type = "text" name = "img1"/> </div> <br> <div class = "form-control"> <input type = "text" name = "name2"/> <input type = "text" name = "num2"/> <input type = "text" name = "img2" /> </Div> <br> <div class = "form-control"> <input type = "text" name = "name3"/> <input type = "text" name = "num3"/> <input type = "text" name = "img3"/> </div> ...... <input type = "submit" value = "Submit"/> </form> Service (index. php) just a few simple words <? Phpecho "<pre>"; print_r ($ _ GET ); fill in the following information on the rendered webpage and click Submit. The Query String Paramaters displayed in the browser is like this. In the service segment, this information will be received, which may not be very easy to process with the backend, if we can put three pieces of information in the same group in an array, isn't it much easier to process, next, let's take a look at another method. The second method is the array method for form submission. <form id = "form1" action = ". /index. php "method =" get "> <div class =" form-control "> <input type =" text "name =" infos [1] [name] "/> <input type = "text" name = "infos [1] [num]"/> <input type = "text" name = "infos [1] [img]"/> </ div> <br> <di V class = "form-control"> <input type = "text" name = "infos [2] [name]"/> <input type = "text" name = "infos [2] [num] "/> <input type =" text "name =" infos [2] [img] "/> </div> <br> <div class = "form-control"> <input type = "text" name = "infos [3] [name]"/> <input type = "text" name = "infos [3] [num] "/> <input type =" text "name =" infos [3] [img] "/> </div> ...... <input type = "submit" value = "Submit"/> </form> you can check the name of the data to be submitted. The word name has changed, and it may not be obvious here. After you click Submit, you will find that the value uploaded to the backend is much more neat, let's take a look at the following query string parsed by the browser plug-in. The data printed by the server is like this: when the background receives such data, it will be much easier to process, this saves a lot of trouble. Of course, there are still some points to note. when naming the value to be submitted, no quotation marks are required in the array, note that quotation marks exist in the backend key values after quotation marks are added. Another thing to note is that the more popular practice is ajax submission. How can I obtain the values in the form when I use ajax for submission? In fact, it is very easy to use the serialize () method provided by jquery to easily splice all the content to be submitted into a url string, and then submit it to the background through the get method. Of course, you may also encounter such a problem. The number of groups to be submitted (such as the numbers 1, 2, and 3 above) is uncertain and can be added at Will on the front end, in this case, how can I use arrays to submit the content? This can still be easily solved through appropriate and clear, <form id = "form1" action = ". /index. php "method =" get "> <div class =" form-control "> <input type =" text "name =" infos [name] [] "/> <input type = "text" name = "infos [num] []"/> <input type = "text" name = "infos [img] []"/> </div> <br> <div class = "form-control"> <input type = "text" name = "infos [name] []"/> <input type = "text" name = "infos [num] []"/> <input type = "text" name = "infos [img] []"/> </div> <Br> <div class = "form-control"> <input type = "text" name = "infos [name] []"/> <input type = "text" name = "infos [num] []"/> <input type = "text" name = "infos [img] []"/> </div> ...... <input type = "submit" value = "Submit"/> </form> first, check the data transmitted by the browser. The data received by the backend is like this, it is also easy to classify each group of information. Is it very convenient? before using this method, I had a headache every time I encountered such a problem. Now I can easily solve it.