-4

大家好,我有设置为 action = something.php 的 html 表单。现在我想在单击表单上的提交按钮时自动提交此表单 9 次。我可以用 PHP 做到这一点吗?提前致谢。

4

4 回答 4

0

您想将表单提交 9 次到同一个 PHP 脚本,还是只想处理提交 9 次?不要认为你可以从 PHP 做前者,但后者可以通过循环轻松处理:

for ( $counter = 0; $counter < 9; $counter += 1) {
    \\ do your stuff
}

您是否有特定原因要提交表单而不是多次运行逻辑?

于 2012-09-27T18:42:00.110 回答
0

由于 PHP 是服务器端脚本,因此您实际上无法提交 9 次表单。但是,您可以在 for 循环中对服务器端的数据执行 9 次您正在执行的操作。

for($i = 0; $i < 9; $i++) {
    // use $_POST here and do your stuff

}
于 2012-09-27T18:42:23.683 回答
0

No, you can't do this in PHP. At least not the way you are thinking of doing it (actual multiple POST actions from your form page). The action of posting will automatically take the user to the page you are posting to, not giving you an opportunity to POST again. You could of course POST to another script form the script you POSTed to, but I don;t think this is what you are asking.

To make actual repeated physical POSTs you would likely need to use AJAX methods.

于 2012-09-27T18:44:31.370 回答
0

网页

<form id="form1" name="form1" method="post" action="form.php">
  <input type="text" name="name" id="name" />
  <input type="text" name="email" id="email" />
  <input type="submit" name="button" id="button" value="Submit" />
</form>

PHP 页面

<?php
for($i=1; $i<=9; $i++) {
// Your posting stuff

echo $_POST['name'];
echo '<br>';
echo $_POST['email'];
echo '<br>';
}
?>

这是您可以使用的方式。

于 2012-09-27T18:52:53.157 回答