提交表单时,如何通过$ _POST从php中的动态输入字段数组获取值?

时间:2018-07-18 12:38:41

标签: php arrays input dynamic field

   i have this input field in my form.

     <input type="text" name="<?=$row['picture_id'] ?>-link[]" id="link" value="<?=$row['link'];?>" size="20" />

$row['picture_id']  is the id coming from database and input field on front end showing value like www.xyz.com .

我做了print_r($ _ POST); 我得到了...。

Array ( [539-link] =>Array ( [0] => Array) [450-link] => Array([0]=> Array)) like that but on front end side input field is showing link only like www.xyz.com and www.txy.com

I want to get values of this input field when form is submitted .Form has 'method="post" action="footer_images.php"'.

2 个答案:

答案 0 :(得分:0)

您可以在名称之前添加前缀,这样您就可以找到以您设置的前缀开头的_POST变量,可以使用substr或其他方法进行检查。

答案 1 :(得分:0)

<input type="text" name="<?=$row['picture_id'] ?>-link[]" id="link" value="    <?=$row['link'];?>" size="20" />
//put another input hidden
<input type="hidden" name="pictureId" value="<?=$row['picture_id'];?>" size="20" />
//in footer_images.php
if ( isset($_POST['pictureId']) ){
$id = $_POST['pictureId'] ;
//your value 
if ( isset($_POST[$id.'link']) )
    echo $_POST[$id.'link'];//your value 
}