Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

POST with two buttons

Status
Not open for further replies.

plarsen

Programmer
Jul 30, 2002
27
DK
Hi all

I hope someone can help me with this small but annoying problem.

I have search for help, but was not able to find any on this issue.

On a page I have a list with a checkbox in front of each line there the user can select multiple and then click either a approve button or a decline button.

the list:

<form action="?mode=admin_images" method="post">
<table class="admin_images">
<tr>
<td style="text-align:center">
<input type="checkbox" id="check_13" name="check[]" value="6524"/>
</td>
<td>
<a href="#" onclick="popup('popup.php?mode=profile&amp;id=1476',800,600,'popup');"></a>
</td>
<td>
<a href="#" onclick="previewImage('/pics/bild2.jpg',351,368);">/pics/bild2.jpg<span class="popup"><span style="font-weight:bold;text-decoration:underline;">Reason:</span><br /></span></a><!--[if IE]>
<div><span class="title">Reason:</span><br /></div><![endif]-->
</td>
<td style="text-align:center">19,99 KB</td>
<td style="text-align:center">3</td>
<td style="text-align:center">2005-02-25 23:47:03</td>
<td style="text-align:center"></td>
<td style="text-align:center">
<a href="?mode=admin_images&amp;accept_img=6524"><img src="img/button_green1.png" alt="ok" style="border:none" /></a>
</td>
<td style="text-align:center">
<a href="?mode=admin_images&amp;decline_img=6524"><img src="img/button_red.png" alt="ok" style="border:none" /></a>
</td>
</tr>
<tr>
<td style="text-align:center">
<input type="checkbox" id="check_14" name="check[]" value="6525"/>
</td>
<td>
<a href="#" onclick="popup('popup.php?mode=profile&amp;id=1476',800,600,'popup');"></a>
</td>
<td>
<a href="#" onclick="previewImage('/pics/bild3.jpg',176,420);">/pics/bild3.jpg<span class="popup"><span style="font-weight:bold;text-decoration:underline;">Reason:</span><br /></span></a><!--[if IE]>
<div><span class="title">Reason:</span><br /></div><![endif]-->
</td>
<td style="text-align:center">9,17 KB</td>
<td style="text-align:center">3</td>
<td style="text-align:center">2005-02-25 23:49:39</td>
<td style="text-align:center"></td>
<td style="text-align:center">
<a href="?mode=admin_images&amp;accept_img=6525"><img src="img/button_green1.png" alt="ok" style="border:none" /></a>
</td>
<td style="text-align:center"><a href="?mode=admin_images&amp;decline_img=6525"><img src="img/button_red.png" alt="ok" style="border:none" /></a>
</td>
</tr>
</table>
</form>

the buttons:

<button type="submit" id="accept_img" name="accept_img" value="1" title="Accept selected images" class="submit">
<img src="img/button_green1.png" alt="Accept">
</button>

<button type="submit" id="decline_img" name="decline_img" value="0" title="Decline selected images" class="submit">
<img src="img/button_red.png" alt="Decline">
</button>

The issue:
Then the page i submitted i want to check whether the user clicked accept or decline.

I have the following script that should do that but doesn't.

It always executes the first foreach.

<?
if (isset($_POST['accept_img'])) {
foreach ($_POST['check'] as $id) {
$img = new Image($id);
$_SESSION['DELETEIMAGE'] = $_POST['accept_img'];
$_SESSION['DELETEIMAGE'] .= "POST_ACCEPT";
$img->status = 1;
$img->save();
}

ob_clean();
if (isset($_POST['query_string'])) header("Location: ?$_POST[query_string]");
else header("Location: ?mode=admin_images&status=0");
ob_end_flush();
exit;
}
elseif (isset($_POST['decline_img'])) {
foreach ($_POST['check'] as $id) {
$img = new Image($id);
$_SESSION['DELETEIMAGE'] = $_POST['decline_img'];
$_SESSION['DELETEIMAGE'] .= "POST_DECLINE";
$img->delete();
$img->save();
}

ob_clean();
if (isset($_POST['query_string'])) header("Location: ?$_POST[query_string]");
else header("Location: ?mode=admin_images&status=0");
ob_end_flush();
exit;
}
?>

I'm looking forward to some tips on how to deal with this problem.

Thanks

/Peter Larsen
 
Those button images are surrounded by anchor ("<A>") tags. And the href attributes of those anchors appear to be relative references back to the script that generates the page.

If this is so, clicking on the image will not submit the form at all, so there can be no data in $_POST. Rather, you are submitting data through the URL, which will appear in $_GET.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
The images surrounded by <A> tag isn't those that give me trouble, it is the two button with the <Button> tag.

The images that submits through the URL, are working as they should.

/Peter
 
the buttons:

<button type="submit" id="accept_img" name="accept_img" value="1" title="Accept selected images" class="submit">
<img src="img/button_green1.png" alt="Accept">
</button>

<button type="submit" id="decline_img" name="decline_img" value="0" title="Decline selected images" class="submit">
<img src="img/button_red.png" alt="Decline">
</button>

/Peter
 
It is place inside the form-tag below the list!

</td>
</tr>
</table>

<button type="submit" id="accept_img" name="accept_img" value="1" title="Accept selected images" class="submit">
<img src="img/button_green1.png" alt="Accept">
</button>

<button type="submit" id="decline_img" name="decline_img" value="0" title="Decline selected images" class="submit">
<img src="img/button_red.png" alt="Decline">
</button>

</form>

/Peter
 
That's not what you originally posted.


The problem is that having the two buttons in the form causes different browsers to behave differently. Opera only sends information about the button that was clicked. IE sends the same information about both, regardless of which is clicked.

I recommend that you not use <button> tags at all, but rather <input type="image"> tags. They behave better, and after all, you're just using the buttons with images.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top