点击每个按钮提交表单


form submit on each button click

我的代码是

<form action="test.php" name="test">
<?php foreach($result as $res)
{
 ?>
  <div>
  <label><?php echo $res->name;?></label>
    <input type="text" name="<?php echo $res->val;?>">
    <input type="submit" value="submit" />
  </div>
<?php }
?>
</form>

我需要对每个提交按钮执行相同的操作,每当用户单击它时,都应该调用操作test.php。我试过这样做,但没有用。请帮忙。

对于每个提交,您需要一个不同的表单

<?php foreach($result as $res)
{
echo "<form action='"test.php'" name='"".$res->name."'">";
 ?>
  <div>
  <label><?php echo $res->name;?></label>
  <input type="text" name="<php echo $res->val;?>">
  <input type="submit" value="submit"
  </div>
<?php
echo "</form>";
 }
?>

首先,看看控制结构的替代语法。