Multiple Submit Buttons PHP Rookie
Posted: Sat Sep 09, 2006 9:44 am
feyd | Please use
With my poor code, When one of the submit buttons is pressed, all edit[] buttons are considered posted, so the textbox always ends up witht he last value in the array "Kangaroo".
I wish to figure out how to tell WHICH Edit[] Button was pressed so I can get the appropriate array value.
edit[1] = PRESSED;
array[1]=Stork;
textvalue=Stork;
I hope my yammering made sense!
-Dom
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I am sure the solution here is simple... but I am not quite sure where to start my [b]Search[/b] in the forums
Within an HTML Form, I have an array that posts a string as well as an "EDIT" button with it (type="submit" name="edit[]").
Upon pressing the "EDIT" button, I wish to have the textbox fill with the appropriate string in the array.Code: Select all
<table>
<form method="POST" name="EditTest" action="<? $_SERVER['PHP_SELF']; ?>">
<?php
$array1 = array("Monkey", "Stork", "Kangaroo");
$EditIt ="";
//If the button is pressed, Fill the textbox with the given array value
if (isset($_POST['edit'])) //Edit Database Value
{
for($i=0;$i<3;$i++)
{
if (isset ($_POST['hEdit'][$i]))
{
$Pressed = $_POST['hEdit'][$i];
$EditIt = $array1[$i];
echo "$Pressed <br>";
}
}
echo<<<EOD
<tr><td colspan="3">
<input type="text" name="dogPrice" size="26" value="$EditIt">
</td></tr>
EOD;
}
else
{
echo<<<EOD
<tr><td colspan="3">
<input type="text" name="dogPrice" size="26" value="">
</td></tr>
EOD;
}
for($i=0;$i<3;$i++)
{
echo<<<EOD
<tr><td> $array1[$i]
<input type="submit" value="Edit" name="edit[]">
<input type="hidden" value="$i" name="hEdit[]">
</td></tr>
EOD;
}
?>
</form>
</table>I wish to figure out how to tell WHICH Edit[] Button was pressed so I can get the appropriate array value.
edit[1] = PRESSED;
array[1]=Stork;
textvalue=Stork;
I hope my yammering made sense!
-Dom
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]