hikzero Posted February 23, 2010 Share Posted February 23, 2010 Hello forum, im new so go easy on me. In a html form, how do i set the action so that if i have 3 <input> buttons that call different php functions still work? like I want 3 different buttons to be able to call upon each of the three different functions depending on which one is pressed. all php code is on the same page but i don't know what to put in the action attribute of my html form Can someone give me an example Quote Link to comment https://forums.phpfreaks.com/topic/193057-php-question/ Share on other sites More sharing options...
hikzero Posted February 23, 2010 Author Share Posted February 23, 2010 erm, anyone? Quote Link to comment https://forums.phpfreaks.com/topic/193057-php-question/#findComment-1016977 Share on other sites More sharing options...
Grayda Posted February 25, 2010 Share Posted February 25, 2010 Be patient. Not everyone here visits on a daily basis, nor do they get paid for their help. In response to your question, you can do something like this: <form action="test.php" method="post"> <input type="submit" value="One" name="choice[]" /> <input type="submit" value="Two" name="choice[]" /> <input type="submit" value="Three" name="choice[]" /> </form> <?php if($_POST["choice"][0] == "One") { echo "One clicked"; } elseif($_POST["choice"][0] == "Two") { echo "Two clicked"; } elseif($_POST["choice"][0] == "Three") { echo "Three clicked"; } elseif(empty($_POST)) { } else { echo "Uh oh, hacking attempt! lol"; } ?> By adding [] to the end of an input's name, you turn it in to an array (akin to $blah[] = "Hello"; $blah[] = "World"; ) so you can add 100 buttons, all with the same name and echo out $_POST["blah"][0] to find out which one was clicked. If you do the same with checkboxes or listboxes with multiple="multiple", you can find out exactly which boxes were ticked. For example: <?php for($i = 0; $i <= 100; $i++) { echo "Was $i clicked?: " . $_POST["blah"][$i] . "<br />"; } ?> Hope that helps! And remember that your answer might take a few days or even a few weeks to be answered. It's whoever stops by and knows the answer. If you're looking for immediate answers, try a company that does telephone support for PHP Quote Link to comment https://forums.phpfreaks.com/topic/193057-php-question/#findComment-1017848 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.