开发者

how to get post element in form in this case( in PHP )

开发者 https://www.devze.com 2022-12-13 14:33 出处:网络
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.....

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 on开发者_如何学运维ly 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>


<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];


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消