将HTML个表单数据作为文本,发送到html2pdf

Taking HTML Form data as text, sending them to html2pdf

如何将此表单数据作为 text/string 发送到 html2pdf 函数?我想通过 css 提交按钮下载 pdf。

表单和JS代码:

<form action= method=  enctype="text/plain">

    <label for="fname">Adı</label>
    <input type="text" id="fname" name="firstname" placeholder="Adınız">

    <label for="lname">Soyadı</label>
    <input type="text" id="lname" name="lastname" placeholder="Soyadınız">

    <label for="country">Başvurulacak Birim</label>
    <select id="country" name="country">
      <option value="australia">Pazarlama</option>
      <option value="canada">Sosyal Medya Yönetimi</option>
      <option value="usa">Ürün Tasarımı</option>
    </select>

    <label for="subject">Subject</label>
    <textarea id="subject" name="subject" placeholder="Burada kendinizi tanıtın..." style="height:200px"></textarea>

    <input type="submit" onclick="Fonksiyon();" value="İNDİR">

  </form>
             
<script>
                 
function Fonksiyon() {
var element = document.getElementById('element-to-print');
html2pdf(element);
          }
</script>

两点 -

  1. id 添加到您的 form。由于您在 Fonksiyon 函数中通过 element-to-print 引用它 -

    <form id ="element-to-print">

  2. 将输入类型从 submit 更改为 button,您在此处调用函数 Fonksiyon -

    <input type="button" onclick="Fonksiyon();" value="İNDİR">

Working fiddle.