ali_2kool2002 Posted February 13, 2007 Share Posted February 13, 2007 can anyone code some basic php to create 4 buttons in a loop , and once created a handling form checks which button is pressed and outputs the value in the hidden input on that button? Link to comment https://forums.phpfreaks.com/topic/38309-solved-how-to-create-buttons-in-a-loop/ Share on other sites More sharing options...
obsidian Posted February 13, 2007 Share Posted February 13, 2007 Try something like this: <?php if (isset($_POST['submitted'])) { $button = 0; foreach ($_POST as $k => $v) { if (preg_match('|^sub_([\d]+)\z|', $k, $match)) { $button = $match[1]; } } echo "<p>Button $button pressed!</p>\n"; } ?> <form name="myForm" action="" method="post"> <input type="hidden" name="submitted" value="y" /> <?php for ($i = 1; $i < 5; $i++) { echo "<input type=\"submit\" name=\"sub_{$i}\" value=\"Button $i\" /><br />"; } ?> </form> Hope this helps Link to comment https://forums.phpfreaks.com/topic/38309-solved-how-to-create-buttons-in-a-loop/#findComment-183597 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.