我正在尝试$ _POST提交此表单时的两个变量,它会在选择图像时自动提交,这很好。但它只发布图像值,而不是隐藏值,我需要发送两个变量,因此两个输入的变量都需要提交。单独地,它们工作正常,如果我将隐藏的输入更改为图像,它会愉快地发布值,但同样,它本身不是两个输入。有任何想法吗?
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<?php
$query = $conn->prepare("SELECT name, project FROM models.models where models.active = 'yes'");
$query->execute();
while($r = $query->fetch(PDO::FETCH_OBJ)){
echo "
<input type='image' style='height:100px; padding:5px; margin :20px;' id='1' class='img-fluid img-thumbnail' src='models/thumbs/",$r->name,".jpg' name='name' value='",$r->name,"'/>
<input type='hidden' id='1' name='group' value='",$r->project,"'/>
";
}
?>
</form>
答案 0 :(得分:1)
基于我们评论的候选解决方案,将输入图像更改为按钮,在单独的标记中显示图像并将列表拆分为多种形式:
<?php
$query = $conn->prepare("SELECT name, project FROM models.models where models.active = 'yes'");
$query->execute();
while($r = $query->fetch(PDO::FETCH_OBJ)){ ?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<img style='height:100px; padding:5px; margin :20px;' src="models/thumbs/<?php echo $r->name; ?>.jpg" />
<input type="submit" name="name" value="<?php echo $r->name; ?>" />
<input type='hidden' id='1' name='group' value='",$r->project,"'/>
</form>
<?php
}
?>