tags:

views:

86

answers:

2

in a form which is handled by php language, how can we get a input elements which are in a kind of array like item1,item2,item3..... (if we only want those items that are having values)

example:-
<form method="post" action="<?php echo $PHP_SELF;?>">
item1 <input type="text" name="item1">
item2 <input type="text" name="item2">
item3 <input type="text" name="item3">
<input type="submit" value="submit" name="submit"> 
</form>
A: 

Do you mean beyond what's in the $_POST array? That contains everything submitted to the page.

So you can say something like

if (isset($_POST['item1'])){
    echo $_POST['item1'];
}

(Obviously beyond echoing it, you can save it to a DB, do operations on it and print it back to the page somehow, or whatever you're using the form for)

Alex Mcp
+3  A: 
<form method="post" action="<?php echo $PHP_SELF;?>">
item1 <input type="text" name="item[]">
item2 <input type="text" name="item[]">
item3 <input type="text" name="item[]">
<input type="submit" value="submit" name="submit"> 
</form>

Then in php

$inputarray = $_REQUEST['item'];

echo $inputarray[0];
nullptr
For reference: http://www.php.net/manual/en/faq.html.php#faq.html.arrays
outis