简体   繁体   中英

Download pdf files in php

Actually in my website have some download pdf button (separate separate pdf files) when i'm click that download pdf button that time will open one pop up form, that have two filed (name and email) i filed that field after will submit means that time will download a related pdf files so how will work please any one help me.

Here my Html code:

 <div class="pdfdwnld">
    <a href="javascript:;" class="pdfbtn" data-toggle="modal" data-target="#myModal">Download Pdf</a>
  </div>

<div class="modal fade in" id="myModal" role="dialog">
                   <div class="modal-dialog modal-lg">
                    <form data-toggle="validator" role="form" id="frm">
                      <div class="modal-content col-lg-6 text-center">
                        <div class="modal-header">
                          <button type="button" class="close" data-dismiss="modal" style="margin-bottom: 10px;">&times;</button>
                          <h5 class="modal-title text-center">Submit your E-Mail for Download PDF</h5>
                        </div>
</div>

                      </div>
                  </form>
                      </div>
                 </div>

From what I'm able to understand you have:

  1. A page with a button.
  2. When you click on that button a modal pops up with a form,
  3. In that form you have two input fields: name and email.
  4. Once you submit the form a PDF should be downloaded.

To do this you should change your HTML a bit

  • Add a method and action to your form tag (the action is the link to your PHP file that will handle the download)
  • Add your name and email input fields to your form
  • Clean up your code (unused </div> s, etc.)
<div class="pdfdwnld">
    <a href="javascript:;" class="pdfbtn" data-toggle="modal" data-target="#myModal">Download Pdf</a>
  </div>
  <div class="modal fade in" id="myModal" role="dialog">
    <div class="modal-dialog modal-lg">
      <!-- Add action and method to form tag -->
      <form action="download.php" method="post" data-toggle="validator" role="form" id="frm">
        <div class="modal-content col-lg-6 text-center">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" style="margin-bottom: 10px;">&times;</button>
            <h5 class="modal-title text-center">Submit your E-Mail for Download PDF</h5>
          </div>
          <!-- Add your input fields -->
          <div class="modal-body">
            <div class="form-group">
              <label for="nameInput">Name</label>
              <input type="text" class="form-control" name="name" id="nameInput" placeholder="Name">
            </div>
            <div class="form-group">
              <label for="emailInput">Email</label>
              <input type="email" class="form-control" name="email" id="emailInput" placeholder="Email">
            </div>
          </div>
          <div class="modal-footer">
            <input type="submit" value="download" class="btn btn-primary">
          </div>
        </div>
      </form>
    </div>
  </div>

From what I can tell from your comments you only have to create the HTML (As in the frontend) (Though I might be misinterpreting it).

If this is the case then someone else (your backend developer) will have to create the functionality to actually download the PDF when the form has been submitted

More information how you can use your php file to download the PDF can be found here: https://stackoverflow.com/a/17310470/4666299

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM