Jump to content

[SOLVED] How to create buttons in a loop?


ali_2kool2002

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.