-4

Hi guys I have html form which is set to action = something.php. now i want to autosubmit this form 9 times when submit button on the form is clicked. can i do this using PHP. Thanks in advance.

11
  • 2
    and why would u want to do it 9 times? inserting 9 rows? Sep 27, 2012 at 18:38
  • I'm with coder1984. I can't conceive of any reason you would post the same data 9 times over.
    – Mike Brant
    Sep 27, 2012 at 18:39
  • it does not have to be 9 times it can be anything more than 1 Sep 27, 2012 at 18:40
  • ok, and what do you want to achieve by doing so? Sep 27, 2012 at 18:40
  • 1
    @user1704273 Why would you want to use 9X the bandwodth for the same file? Just handle the upload in the script being posted to and make 8 copies.
    – Mike Brant
    Sep 27, 2012 at 18:45

4 Answers 4

0

Since PHP is a server side script, you cannot actually submit the form 9 times. You can, however, do whatever you're doing with the data on the server side 9 times in a for loop.

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

}
0

do you want to submit the form 9 times to the same PHP script, or do you just want to handle the submission 9 times? Don't think you can do the former from PHP, but the later would be easily handled via a loop:

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

Do you have a particular reason why you want to submit the form vs. just running through the logic multiple times?

5
  • yes i want to upload one file more than one time to my ftp folder Sep 27, 2012 at 18:45
  • then you should just use a loop, and upload said file n times in the loop. that will achieve what you need, and save you a lot of submissions and whatnot.
    – ShawnW.
    Sep 27, 2012 at 18:51
  • but it overrides the exsisting files Sep 27, 2012 at 18:53
  • if you aren't changing the name of the file each time, then that is to be expected. append the counter to the file name your uploading in the loop, that way each time you upload the file in the loop, it will have a different name and won't overwrite the previously uploaded one.
    – ShawnW.
    Sep 27, 2012 at 18:55
  • @user1704273 POSTing it a bunch of times would have just overwritten the file as well. It seems like you really don;t have a good grasp of how to handle files that are uploaded via form. Maybe read this link: php.net/manual/en/features.file-upload.php
    – Mike Brant
    Sep 27, 2012 at 18:56
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.

1
  • @iccthedral What about cURL? Like I said you could POST repeatedly from within the script handling the POST (you could use cURL, or whatever method you might choose to make POST's in a loop), but you can't really do what the question asks, which is actually submitting the form multiple times using PHP. Even in the case of using cURL or similar to make looping POST's, you would either need to post 9x (or however many) to a separate script than the one POSTed to from the form, or POST to itself with some additional counter parameter being passed/incremented so as to avoid an infinite loop.
    – Mike Brant
    Sep 27, 2012 at 18:52
0

HTML Page

<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 Page

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

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

This is the way you can use.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.