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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Which button has been pushed in a form? 1

Status
Not open for further replies.

warby1212

Programmer
Jun 9, 2003
183
AU
Hi, I have a form using POST which has 3 buttons in it. In the php page that it calls I can't find which button has been pushed (warning newbie).
I'm using
if ($_POST['button_name'])
and that works works if "button_name" is the button I pushed but referring to the other buttons gets me an error.

Basically how can I discover which of several submit buttons on a form has been pushed? (is submit the wrong type?)
Thanks for any help :)


I'm really not in management but I can't change my profile (I'm a programmer)
 
Can you show us some code (i.e. your html form and your PHP so far)?

Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
say you have three buttons: blue yellow and green.

have your html like this

Code:
<input type="submit" name="submit" value="blue" />
<input type="submit" name="submit" value="yellow" />
<input type="submit" name="submit" value="green" />

in your receiving script

Code:
<?
if (isset($_POST['submit'])){
  switch ($_POST['submit']){
    case "blue":
      //do something
      break;
    case "yellow":
     //do somethign
     break;
     case "green":
     //do something
     break;
  }
}
?>
 
Hi Stretchwickster and jpadie,

It works ! I took the sample code and she goes. Very happy :)
I had the "name" of the input wrong, plus I found out php is case sensitive. I program in Progress which is not.

Thanks a lot :)
Cheers Stephen

I'm really not in management but I can't change my profile (I'm a programmer)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top