Home  >  Article  >  Backend Development  >  Array form submission, array form submission_PHP tutorial

Array form submission, array form submission_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:09:451576browse

Array form submission, array form submission

I encountered a problem today. I had to save a lot of form information. After worrying about it for a long time, I finally found a pretty good way to use an array. Submit the data in the form to the background for saving.

In fact, it is very simple to implement, that is, there must be certain standards when naming the information to be submitted in the form. Let us first compare the differences between the following two methods:

The first, common way, 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>

The service (index.php) is as simple as two sentences

<?php
echo "<pre class="brush:php;toolbar:false">";
print_r($_GET);

Fill in the following information on the rendered webpage and click submit

Array form submission, array form submission_PHP tutorialc34e35fe590550d2cb0ed6b55f034579 3cee9a8d0b18a6302b9bcd0167383984 d67d1c6916d586de06cd54bc89138b77 bebf59ef8c8439c367f278a3dc84e8de b595b15932d5061b95b8895e080ca4b3 16b28748ea4df4d9c2150843fecfba68 0c6dc11e160d3b678d68754cc175188a 3cee9a8d0b18a6302b9bcd0167383984 b1649b14a4a59b88be5a1d5a1d4dac58 51ee2983449a09fee5e6185ae0c74fa6 b2fd8163d625e7f1fab4efff9734205d 16b28748ea4df4d9c2150843fecfba68 0c6dc11e160d3b678d68754cc175188a 3cee9a8d0b18a6302b9bcd0167383984 b8647bd2437bd10ac4ca2e41b70416d3 e8d45f1d6fd1921d9efc86f921859e6c 75c423362b6639dfae3cd066f1cc92bc 16b28748ea4df4d9c2150843fecfba68 ... 92e8cbd9feac6a729893ae422743759e f5a47148e367a6035fd7a2faa965022e

If you look carefully, you will find that the name of the data to be submitted has changed. It may not be obvious here. When you click submit, you will find that the values ​​​​passed to the backend are much neater. Take a look at the screenshot below

The query string parsed through the browser plug-in is like this

Array form submission, array form submission_PHP tutorialc34e35fe590550d2cb0ed6b55f034579 3cee9a8d0b18a6302b9bcd0167383984 7d7922467785a37a1b03606247e54d4a 83538388f29f52d6dbc5f7ae73c80677 0ccf0a0c3d9de4a2f15686ecf769d2c4 16b28748ea4df4d9c2150843fecfba68 0c6dc11e160d3b678d68754cc175188a 3cee9a8d0b18a6302b9bcd0167383984 7d7922467785a37a1b03606247e54d4a 83538388f29f52d6dbc5f7ae73c80677 0ccf0a0c3d9de4a2f15686ecf769d2c4 16b28748ea4df4d9c2150843fecfba68 0c6dc11e160d3b678d68754cc175188a 3cee9a8d0b18a6302b9bcd0167383984 7d7922467785a37a1b03606247e54d4a 83538388f29f52d6dbc5f7ae73c80677 0ccf0a0c3d9de4a2f15686ecf769d2c4 16b28748ea4df4d9c2150843fecfba68 ... 92e8cbd9feac6a729893ae422743759e f5a47148e367a6035fd7a2faa965022e

First look at the data passed by the browser

 Array form submission, array form submission_PHP tutorial The copyright of this article belongs to the author iforever (luluyrt@163.com). Any form of reprinting is prohibited without the author's consent. After reprinting the article, the author and the original text link must be given in an obvious position on the article page, otherwise we will reserve the right to pursue it. Legal liability rights.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/942278.htmlTechArticleSubmit the form in array mode. I encountered a problem when submitting the array form today. I have to save a lot of form information. I have been worrying about it for a long time. , finally found a pretty good method, in the form of an array...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn