Jump to content

Recommended Posts

Lets say that I have a content area and 2 buttons on a template:

 

button1:

<form action="#" method="POST">
<input  type="image" src="http://www.newcomedy.net/imgs/button_01.gif" />
</form>

 

and button2:

<form action="#" method="POST">
<input  type="image" src="http://www.newcomedy.net/imgs/button_02.gif" />
</form>

 

if I press the first button I'll get some text in the content area... and if I press the second button I'll get some other text.

Is that possible?

 

Link to comment
https://forums.phpfreaks.com/topic/41131-is-this-possible/
Share on other sites

Yeah. Give the buttons names and then check which button was pressed. Example:

 

<form action="#" method="POST">
<input name="button1"  type="image" src="http://www.newcomedy.net/imgs/button_01.gif" />
</form>

<form action="#" method="POST">
<input name="button2" type="image" src="http://www.newcomedy.net/imgs/button_02.gif" />
</form>
<br><br>

<?php
if(isset($_POST['button1']))
echo "Button1 was pressed";
elseif(isset($_POST['button2']))
echo "Button2 was pressed";
else
echo "None of the buttons were pressed";
?>

 

 

Hope it helps :)

Orio.

Link to comment
https://forums.phpfreaks.com/topic/41131-is-this-possible/#findComment-199234
Share on other sites

post the form to itself.

 

<form action="test.php" method="POST">
<input name="button1"  type="image" src="http://www.newcomedy.net/imgs/button_01.gif" />
</form>

<form action="test.php" method="POST">
<input name="button2" type="image" src="http://www.newcomedy.net/imgs/button_02.gif" />
</form>
<br><br>

<?php
if(isset($_POST['button1']))
echo "Button1 was pressed";
elseif(isset($_POST['button2']))
echo "Button2 was pressed";
else
echo "None of the buttons were pressed";
?>

Link to comment
https://forums.phpfreaks.com/topic/41131-is-this-possible/#findComment-199250
Share on other sites

does your button MUST be of an image type?

 

if you can use regular submit buttons, this will work (tested):

<form action="#" method="POST">
<input name="button1"  type="submit" />

<input name="button2" type="submit" />
</form>

<?php
if(isset($_POST['button1'])) {
echo "Button1 was pressed";
} elseif(isset($_POST['button2'])) {
echo "Button2 was pressed";
} else {
echo "None of the buttons were pressed";
}
?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/41131-is-this-possible/#findComment-199265
Share on other sites

My mistake, they are buttons so it should be this way:

 

<form action="#" method="POST">
<input name="button1"  type="image" src="http://www.newcomedy.net/imgs/button_01.gif" />
</form>

<form action="#" method="POST">
<input name="button2" type="image" src="http://www.newcomedy.net/imgs/button_02.gif" />
</form>
<br><br>

<?php
if(isset($_POST['button1_x']))
echo "Button1 was pressed";
elseif(isset($_POST['button2_x']))
echo "Button2 was pressed";
else
echo "None of the buttons were pressed";
?>

 

 

Orio.

Link to comment
https://forums.phpfreaks.com/topic/41131-is-this-possible/#findComment-199270
Share on other sites

If you use an image as a submit button, then the values returned are the x and y co-ordinates of your click relative to the top left corner of the image. Those values are returned as $_POST['submit_x'] and $_POST['submit_y'] for a button NAMEd submit.

 

Check for submit_x or submit_y being set and you'll have your form working in no time.

 

ok, Orio's noted it.

Link to comment
https://forums.phpfreaks.com/topic/41131-is-this-possible/#findComment-199274
Share on other sites

<form action="test.php" method="POST">
<input name="button1"  type="image" src="http://www.newcomedy.net/imgs/button_01.gif" />
</form>

<form action="test.php" method="POST">
<input name="button2" type="image" src="http://www.newcomedy.net/imgs/button_02.gif" />
</form>
<br><br>

<?php
if(!isset($_POST['button1_x'] && ($_POST['button2_x']))
echo "None of the buttons were pressed";
elseif(isset($_POST['button2_x']))
echo "Button 2 was pressed";
elseif(isset($_POST['button1_x']))
echo "Button 1 was pressed";
?>

 

Snooble

 

(Balls. Orio is too damn fast, i had to look at my code)

Link to comment
https://forums.phpfreaks.com/topic/41131-is-this-possible/#findComment-199276
Share on other sites

Snooble, what do u mean?

 

 

this is my bottom code for the normal site:

<table border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td width="212" height="51" background="http://www.newcomedy.net/imgs/home_06.gif">
</td>
<td width="168" height="51" background="http://www.newcomedy.net/imgs/button_01.gif">
<a href="http://www.newcomedy.net/home/business/" title="tryk her for at komme til business sektionen" onmouseover="businessOver()" onmouseout="businessOut()">
<img border="0" src="http://www.newcomedy.net/imgs/button_01.gif" alt="business info" name="business">
</a>
</td> 
<td width="116" height="51" background="http://www.newcomedy.net/imgs/home_08.gif"> 
</td>
<td width="168" height="51" background="http://www.newcomedy.net/imgs/button_02.gif">
<a href="http://www.newcomedy.net/home/creative/" title="tryk her for at komme til creative sektionen" onmouseover="creativeOver()" onmouseout="creativeOut()">
<img border="0" src="http://www.newcomedy.net/imgs/button_02.gif" alt="creative info" name="creative">
</a>
</td>
<td width="234" height="51" background="http://www.newcomedy.net/imgs/home_10.gif"> 
</td>
</tr>
</table>

 

 

Test.php bottom code:

<table border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td width="212" height="51" background="http://www.newcomedy.net/imgs/home_06.gif">
</td>
<td width="168" height="51" background="http://www.newcomedy.net/imgs/button_01.gif">
<form action="test.php" method="POST">
<input name="button1" type="image" src="http://www.newcomedy.net/imgs/button_02.gif" />
</form>
</td> 
<td width="116" height="51" background="http://www.newcomedy.net/imgs/home_08.gif"> 
</td>
<td width="168" height="51" background="http://www.newcomedy.net/imgs/button_02.gif">
<form action="test.php" method="POST">
<input name="button2" type="image" src="http://www.newcomedy.net/imgs/button_02.gif" />
</form>
</td>
<td width="234" height="51" background="http://www.newcomedy.net/imgs/home_10.gif"> 
</td>
</tr>
</table>

Link to comment
https://forums.phpfreaks.com/topic/41131-is-this-possible/#findComment-199316
Share on other sites

Ok, I solved the problem with the design. But now the form script won't work  ???

 

www.newcomedy.net/home

 

php code:

 

<?
if(isset($_POST['button1_x']))
    echo "Button1 was pressed";
elseif(isset($_POST['button2_x']))
    echo "Button2 was pressed";
else
    echo "None of the buttons were pressed";
?>

Link to comment
https://forums.phpfreaks.com/topic/41131-is-this-possible/#findComment-200336
Share on other sites

As I posted in my other topic, the PHP code for www.newcomedy.net/home looks like this:

 

<?

if(isset($_POST['button1_x']))

    echo "Button1 was pressed";

elseif(isset($_POST['button2_x']))

    echo "Button2 was pressed";

else

    echo "None of the buttons were pressed";

?>

 

The problem is that I allways get the "None of the buttons were pressed" text, though i pressed one of the buttons.

Link to comment
https://forums.phpfreaks.com/topic/41131-is-this-possible/#findComment-200618
Share on other sites

<form action="#" method="POST">

<input name="button1"  type="submit"  value="image" src="http://www.newcomedy.net/imgs/button_01.gif" />

</form>

 

<form action="#" method="POST">

<input name="button2" type="submit"  value="image"  src="http://www.newcomedy.net/imgs/button_02.gif" />

</form>

<br><br>

 

<?php

if(isset($_POST['button1'])){

echo "Button1 was pressed";

}else{

        if(isset($_POST['button2']))

  echo "Button2 was pressed";

}else{

echo "None of the buttons were pressed";

}

?>

Link to comment
https://forums.phpfreaks.com/topic/41131-is-this-possible/#findComment-200627
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.