How to fetch the GET/POST elements in a form without knowing the name of the controls inside the form
I had the list of items. When the user clicks a item, a div is generated with a textbox:
<input type="text" name="(DYNAMICALLY ASSIGNED VALUE)" />
So user can select multiple items. For each item a textbox is generated dynamically inside the form. When the user clicks t开发者_StackOverflow中文版he submit button, I want to fetch the GET/POSTED elements. How can we achieve that?
You can use a for-each loop:
foreach ($_GET as $get_key => $get_value)
You could use a foreach
loop on $_POST
like Matthew suggested or you could set the names of the inputs as an array
for example
<input type="text" name="foo[]">
foreach ($_POST['foo'] as $key => $value) {
...
}
The data would look like something like this
[foo] => Array
(
[0] => ...
[1] => ...
[2] => ...
[3] => ...
)
精彩评论