0

I have that code that make me download images from other wepsite to my wepsite and after a click on submit the page is reload. I want to stop page from reload. the code I put it in some plugin in wordpress.enter image description here

the code that I put in the plugin 
<form action="zip.php" method="POST">
<h2 class="inputmanga"> manga name:</h2></p>
<input type="text" name="name">
<h2 class="inputmanga"> image url:</h2></p>
<input type="text" name="img">
<h2 class="inputmanga"> image numper :</h2>
<input type="text" name="num"><br><br>
<input class="sumbitmanga" type="submit" value="Get!">

the php code that I put in separate folder

$zip = new ZipArchive();
 $my_save_dir = "manga/".$_POST['name'].".zip";
 $zip->open($my_save_dir, ZipArchive::CREATE);
 $num = $_POST['num'];
 for ($i=1; $i <= $num ; $i++) { 
  $url_to_image = $_POST['img'].$i.'.jpg';
  $download_file = file_get_contents($url_to_image);
  $zip->addFromString(basename($url_to_image), $download_file);
  }
  $zip->close();
  echo $my_save_dir . "  Download completed successfully";

2 Answers2

1

You'll need to submit an ajax request to send the email without reloading the page. Take a look at http://api.jquery.com/jQuery.ajax/

$('.submitmanga').click(function() {
$.ajax({
    url: 'zip.php',
    type: 'POST',
    data: {
        // pass required data here
    },
    success: function(msg) {
        alert('successfully sent');
    }               
});

});

The form will submit in the background to the zip.php page which will need to handle the request.

0

This is a repeated question, you do that by listening on the submit event.

https://stackoverflow.com/a/19454346/11028815

Ghonima
  • 2,978
  • 2
  • 14
  • 23