Fruddy Posted March 4, 2007 Share Posted March 4, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/41131-is-this-possible/ Share on other sites More sharing options...
Orio Posted March 4, 2007 Share Posted March 4, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/41131-is-this-possible/#findComment-199234 Share on other sites More sharing options...
Fruddy Posted March 4, 2007 Author Share Posted March 4, 2007 Nope, it's not working :-\ http://www.newcomedy.net/test.php Quote Link to comment https://forums.phpfreaks.com/topic/41131-is-this-possible/#findComment-199245 Share on other sites More sharing options...
Snooble Posted March 4, 2007 Share Posted March 4, 2007 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"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/41131-is-this-possible/#findComment-199250 Share on other sites More sharing options...
play_ Posted March 4, 2007 Share Posted March 4, 2007 form action="#" method="POST"> <input name="button1" type="image" src="http://www.newcomedy.net/imgs/button_01.gif" /> <input name="button2" type="image" src="http://www.newcomedy.net/imgs/button_02.gif" /> </form> try that Quote Link to comment https://forums.phpfreaks.com/topic/41131-is-this-possible/#findComment-199251 Share on other sites More sharing options...
Fruddy Posted March 4, 2007 Author Share Posted March 4, 2007 Snooble, Play_ still not working. Tried both of your ideas. http://www.newcomedy.net/test.php Quote Link to comment https://forums.phpfreaks.com/topic/41131-is-this-possible/#findComment-199259 Share on other sites More sharing options...
play_ Posted March 4, 2007 Share Posted March 4, 2007 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"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/41131-is-this-possible/#findComment-199265 Share on other sites More sharing options...
Orio Posted March 4, 2007 Share Posted March 4, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/41131-is-this-possible/#findComment-199270 Share on other sites More sharing options...
AndyB Posted March 4, 2007 Share Posted March 4, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/41131-is-this-possible/#findComment-199274 Share on other sites More sharing options...
Fruddy Posted March 4, 2007 Author Share Posted March 4, 2007 Well the images needs to be the buttons, and I dont think that submit type can do that. But if this can be done in another way or without using forms, its ok. As long as its going to be the same outcome. I'll try it Orio Quote Link to comment https://forums.phpfreaks.com/topic/41131-is-this-possible/#findComment-199275 Share on other sites More sharing options...
Snooble Posted March 4, 2007 Share Posted March 4, 2007 <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) Quote Link to comment https://forums.phpfreaks.com/topic/41131-is-this-possible/#findComment-199276 Share on other sites More sharing options...
Fruddy Posted March 4, 2007 Author Share Posted March 4, 2007 Thanks very much guys! it works now! But a new problem coming up.. This is the old code from my site: www.newcomedy.net/home It does not come out with the same output in test.php www.newcomedy.net/test.php Quote Link to comment https://forums.phpfreaks.com/topic/41131-is-this-possible/#findComment-199305 Share on other sites More sharing options...
Snooble Posted March 4, 2007 Share Posted March 4, 2007 have you changed the form actions.. Snooble Quote Link to comment https://forums.phpfreaks.com/topic/41131-is-this-possible/#findComment-199306 Share on other sites More sharing options...
Fruddy Posted March 4, 2007 Author Share Posted March 4, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/41131-is-this-possible/#findComment-199316 Share on other sites More sharing options...
Fruddy Posted March 5, 2007 Author Share Posted March 5, 2007 Nobody who knows what might be the problem? :-\ Quote Link to comment https://forums.phpfreaks.com/topic/41131-is-this-possible/#findComment-199704 Share on other sites More sharing options...
Fruddy Posted March 5, 2007 Author Share Posted March 5, 2007 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"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/41131-is-this-possible/#findComment-200336 Share on other sites More sharing options...
AndyB Posted March 5, 2007 Share Posted March 5, 2007 Please post your php code. Looking at the generated html tells us nothing useful. Quote Link to comment https://forums.phpfreaks.com/topic/41131-is-this-possible/#findComment-200377 Share on other sites More sharing options...
Fruddy Posted March 6, 2007 Author Share Posted March 6, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/41131-is-this-possible/#findComment-200618 Share on other sites More sharing options...
Greaser9780 Posted March 6, 2007 Share Posted March 6, 2007 <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"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/41131-is-this-possible/#findComment-200627 Share on other sites More sharing options...
Fruddy Posted March 6, 2007 Author Share Posted March 6, 2007 The type have to be image or else u cant use the src="http://www.newcomedy.net/imgs/button_01.gif". Quote Link to comment https://forums.phpfreaks.com/topic/41131-is-this-possible/#findComment-200644 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.