tags:

views:

56

answers:

2

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 the submit button, i want to fetch the GET/POSTED elements. How can we achieve that?. plz help. Any help will be appreciated.

+5  A: 

You can use a for-each loop:

foreach ($_GET as $get_key => $get_value)
Matthew Flaschen
Can we use it for POST also??
Rajasekar
Yes, they're both just arrays.
Matthew Flaschen
While you're here, it also works for `$_COOKIE`, `$_FILE` and all the other superglobal arrays. Or rather, all other arrays.
zneak
It might be worth adding that it would be wise to ensure that sound security measures are in place, especially when you actually have no idea what the data is you're accepting. If it's dynamic, treat it like nuclear waste.
webfac
+2  A: 

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] => ...
     )
Serge