我有两个表单字段,我想生成一个pdf,其中包含用户在该表单中输入的值。我使用tcpdf来完成任务。我无法获取函数来打印变量的值,而不是打印WriteHtml()函数中输入的内容。如何使代码工作?
HTML:
<html lang="en">
<head>
<title>Some Random PDF</title>
<body>
<h1>Enter relevant details</h1>
<form action="form.php" method="post">
<div class="form-group">
<label for="inputName">Name of the partner</label>
<input type="text" class="form-control" id="inputName" placeholder="" name="inputName">
<span id="inputNameSpan"></span>
</div>
<div class="form-group">
<label for="inputAddress">Address of the partner</label>
<textarea type ="text" class = "form-control" id = "inputAddress" rows = "8" placeholder = "" name="inputAddress"></textarea>
<span id="inputAddressSpan"></span>
</div>
<div class = "form-group">
<center><button type="submit">SEND</button></center>
</div>
</form></center>
</body>
</head>
PHP:
<?php
require_once('TCPDF/tcpdf.php');
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$myName = $_POST['inputName'];
$myAddress = $_POST['inputAddress'];
$pdf->AddPage();
$html= '.htmlspecialchars($myName) lives in .htmlspecialchars($myAddress)';
$pdf->WriteHTML($html);
$pdf->Output();
?>
P.S。
PDF文件中的必需/预期输出($ myName = John,$ myAddress =纽约市)。
约翰住在纽约市
非常感谢任何帮助。提前谢谢!
答案 0 :(得分:0)
$html= '.htmlspecialchars($myName) lives in .htmlspecialchars($myAddress)';
htmlspecialchars是PHP函数,确保它被识别为php脚本而不是字符串
确保你这样写
$html= htmlspecialchars($myName).' lives in '.htmlspecialchars($myAddress);
您需要设置输出类型I / F / FI。更多示例和解释请阅读文档http://www.tcpdf.org/
您可以将示例设置为$pdf->Output('yourfilename','I');