【问题标题】:I'm trying to make html2pdf after a form submitting我正在尝试在提交表单后制作 html2pdf
【发布时间】:2021-10-29 03:30:08
【问题描述】:

当表单为空时,我的 html2padf.js 文件可以工作,但是当我填写表单并提交时,只有表单通过并且该功能不起作用。

window.onload = function () {

document.getElementById("download")
    .addEventListener("click", () => {
        const invoice = this.document.getElementById("invoice");
        console.log(invoice);
        console.log(window);
        var opt = {
            margin: 0,
            filename: 'myfile.pdf',
            image: { type: 'jpeg', quality: 0.98 },
            html2canvas: { scale: 1 },
            jsPDF: { unit: 'in', format: 'letter', orientation: 'portrait' }
        };
        html2pdf().from(invoice).set(opt).save();
    })

}

【问题讨论】:

  • 什么确切不起作用?您尝试过什么来解决问题?你被困在哪里了?
  • 欢迎来到 Stack Overflow!访问help center,使用tour 了解内容和How to Ask。如果您遇到困难,请发布您的尝试minimal reproducible example,并使用[<>] sn-p 编辑器记录输入和预期输出。
  • 此功能适用于表单上提交按钮以外的任何按钮。表单正在提交,但 html2pdf 未通过。我应该给你点别的吗?

标签: javascript php forms


【解决方案1】:

提交后,您的表单将被清除。您可以在提交后添加输入字段的值:

<form action="/action_page.php" method="post">
   <input type="text" name="subject" value="<?php if(isset($_POST['subject'])){echo $_POST['subject'];}?>">
</form> 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-25
    • 1970-01-01
    • 1970-01-01
    • 2017-10-29
    • 1970-01-01
    • 1970-01-01
    • 2021-10-26
    • 1970-01-01
    相关资源
    最近更新 更多