Reputation: 1993
I'm trying to $_POST two variables when this form is submitted, it auto submits when an image is selected, that's fine. But it only posts the image value, not the hidden value, I need both variables to be sent so the variables from both inputs need to submit. Individually they work fine, if I change the hidden input to an image it happily posts the value, but again, only of itself not of both inputs. Any ideas?
<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>
Upvotes: 1
Views: 90
Reputation: 4298
A candidate solution based on our comments, changing the input image to a button, displaying the image in a separate tag and splitting the list into multiple forms :
<?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
}
?>
Upvotes: 1