我在表单上有多个图像以及文本输入。图像需要包含链接,所选链接需要以POST格式提交(因此我可以捕获文本输入字段中的数据)。图像的来源是动态的(因此无法在css文件中设置type =按钮的背景)。以下代码不是实际代码,只是一个示例(请原谅任何基本错误)。我的想法是为每个图像使用<input type=image>
,并使用相应的隐藏字段来存储每个图像的链接。我知道这会奏效。我的问题是,是否有更好或更标准的方式。我知道<input type=image>
用于图像地图,我只是在使用/滥用可用的内容,但我想不出更好的方法。感谢您的投入。
<form method=post action=<?php echo $_SERVER['PHP_SELF'] ?>?dosomething=true enctype='multipart/form-data'>
<?php
$i=0;
foreach ($files as $file){
?>
<input type="text" name='user-input<?php echo $i ?>'>
<input type="image" name='img<?php echo $i ?>' src='<?php echo $file ?>'>
<input type="hidden" name='img<?php echo $i ?>url' value='<?php echo $file ?>'>
<?php
}
?>
加载表单时,请检查帖子值:
foreach ($_POST as $key => $val){
if (substr($key,0,3)=="img"){
$akey = explode("_",$key);
$url = $_POST[$akey[0] . "url"];
// do some processing with user input before leaving form...
header("Location: " . $url);
exit;
}
}