I need to get form data from multiple forms on one page using $_POST

Posted by CDeanMartin on Stack Overflow See other posts from Stack Overflow or by CDeanMartin
Published on 2010-06-17T00:38:37Z Indexed on 2010/06/17 0:42 UTC
Read the original article Hit count: 322

Filed under:
|
|

My project is a menu that displays daily specials at a cafe. The Pointy Haired Boss(PHB) needs to add/remove items from the menu on a daily basis,

so I stored all dishes with MySQL, and created a page which will load all menu items as buttons. When clicked, the button will UPDATE the item, turning it on or off.

I need form data to detect which button was pressed, so my query knows which $menuItem to UPDATE. That is the purpose of the hidden fields.

<html><head></head>
<body>

<html><head></head>
<body>
<?php include("getElement.php");
$keys = array_keys($_POST);
echo $keys[0];
echo $keys[1];
//if(isset($_POST["menuItem"])){
//toggleItem($_POST["menuItem"]);
//echo print_r(array_keys($_POST));}
?>


<form name="b" action="scratchpad.php" method="post" > 
<input type="hidden" name="b" value="Cajun Gumbo"/> 
<input type="submit" style="color:blue" value="Cajun Gumbo" /> </form>

<form name="a" action="scratchpad.php" method="post" > 
<input type="hidden" name="a" value="Guacomole Burger"/> 
<input type="submit" style="color:blue" value="Guacomole Burger" /> </form>


</body> 
</html>

Can I get $_POST to identify which button was pressed?

© Stack Overflow or respective owner

Related posts about php

Related posts about html