【发布时间】:2015-01-21 13:01:32
【问题描述】:
我正在尝试通过 fpdf 将用户输入到 WordPress 联系表 7 中的值导出为 PDF。 这是我设置的,我可以生成 PDF 但没有表单中动态生成的值。
functions.php
add_action( 'wpcf7_before_send_mail', 'save_application_form');
function save_application_form($cf7) {
/* GET EXTERNAL CLASSES */
require(TEMPLATEPATH.'/fpdf/fpdf.php');
$values = $cf7->posted_data;
echo $values['first-name'];
/* example code to generate the pdf */
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Times','B',16);
$pdf->Write(5,'first-name');
$pdf->SetFont('Arial','B',16);
$pdf->Output(TEMPLATEPATH.'/fpdf/pdf.pdf', 'F');
/* add the pdf as attach to the email*/
$cf7->uploaded_files = array ( 'attachedfile' => TEMPLATEPATH.'/fpdf/pdf.pdf' );
如何从联系表格 7 中提取内容? 现在,如果我按发送,我只会得到一个上面写有“名字”的 PDF。我尝试了多种组合,没有任何效果。
感谢您的帮助。
编辑:我已经弄清楚如何打印,但问题似乎是,我没有从联系表 7 中提取插入的内容。
$first_name = $cf7->posted_data["first-name"];
$var = "test";
/* example code to generate the pdf */
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Times','B',16);
$pdf->Write(5, "My car is " . $var . "bl");
$pdf->SetFont('Arial','B',16);
所以 $first_name 不起作用,因为它是空的,有什么想法可以纠正这个问题吗?因为如果我尝试使用 $var 它会起作用。
【问题讨论】:
-
所有
Write都是名字,所以这就是你所得到的。 -
但是如果我插入 $value 我什么都没有显示,你能帮我解决这个问题吗?
-
我已经尝试了另外两种变体。第一次尝试(页面甚至没有加载)
$first_name = $cf7->posted_data["first-name"]; /* example code to generate the pdf */ $pdf = new FPDF(); $pdf->AddPage(); $pdf->SetFont('Times','B',16); $pdf->Write(echo $first_name); $pdf->SetFont('Arial','B',16);第二次尝试,没有任何东西打印到 pdf$first_name = $cf7->posted_data["first-name"]; /* example code to generate the pdf */ $pdf = new FPDF(); $pdf->AddPage(); $pdf->SetFont('Times','B',16); $pdf->Write($first_name); $pdf->SetFont('Arial','B',16);
标签: php wordpress forms pdf fpdf