Jump to content

How to make a html form submit automatically using php


Osram

Recommended Posts

I have the following empty form that needs to be submitted automatically, but which doesn't work:

echo "<form name = \"myform\" id = \"myform\" style= \"margin-left:180px; padding-top:100px\" method=\"post\" action=\"";
echo htmlspecialchars($_SERVER["PHP_SELF"]);
echo "\">";	
echo "<input type=\"hidden\" name=\"Next\"  value =\"1\">";
echo "<input style = \"margin-left:260px\" type=\"submit\" name=\"submit\" value=\"Download\">";
echo "</form>";  
echo "<script>document.getElementById('myform').submit();</script>"; 

The reason I have this form is that I have a downloading routine at the beginning of the script:

if ($_SERVER["REQUEST_METHOD"] == "POST") {
   
   $OK=1;
   
   if($_POST["Next"]==1){
     $exe = "setup.exe";
     header("Content-Type: application/octet-stream"); // binary file
     header("Content-Disposition: attachment; filename=\"setup.exe\""); // download as "Installation-file.exe"
     header("Content-Length: " . filesize($exe)); // tells the browser and user how large the file download will be
     readfile($exe); // dump the file
     exit();
   } 

Can anyone help? Thanks in advance.

 

Link to comment
Share on other sites

Well, the thing is that the script works as it is now by clicking the submit button. The download works fine. The only thing is that I want to avoid having to click the submit button, so that the submit happens automatically.

Link to comment
Share on other sites

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.