Jump to content

php question


Recommended Posts

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

Link to comment
Share on other sites

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[]" />

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:


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 ;D

Link to comment
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.

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.