联系表格7和FPDF [英] Contact Form 7 and FPDF
问题描述
我一直关注wordpress.org上关于保存联系表7中提交的数据并将其作为PDF附件发送给提交者的几个主题。
https://wordpress.org/support/topic/convert-pdf-file
将表格结果从联系表格7导出为PDF(fPDF)
我在我的函数中使用Kory的php并将fpdf上传到我的主题文件中,该文件名为fpdf,并在[attachments]中添加到我在wordpress admin中的联系表单中。
我的错误是联系表格没有提交。只是加载。有什么想法吗?
我的表格 - http://www.mikeandtom.co.uk/ctest
注意到的php错误最初是:' FPDF错误:未定义的字体:times-roman B' - 对此的研究表明应该定义字体文件夹:
I have been following several topics on wordpress.org about saving the data submitted in Contact Form 7 and sending it to the the submitter as a PDF attachment.
https://wordpress.org/support/topic/convert-pdf-file
Exporting form results from Contact form 7 to PDF (fPDF)
Im using Kory's php in my functions and have uploaded fpdf to me theme file in a folder called fpdf plus added in [attachments] to my contact form in wordpress admin.
My error is that the contact form doesn't submit. Just loads. Any ideas?
My Form - http://www.mikeandtom.co.uk/ctest
The php error noted was originally: 'FPDF error: Undefined font: times-roman B' - research on this revealed the font folder should be defined:
define('FPDF_FONTPATH',get_template_directory().'fpdf/font/'); define ('FPDF_PATH',get_template_directory().'/fpdf/');
require(FPDF_PATH.'fpdf.php');
虽然这个'A'无法定义字体定义文件'错误
ALTHOUGH THIS THROWS UP A 'could not define font definition file' error
add_action('wpcf7_before_send_mail', 'wpcf7_update_email_body');
function wpcf7_update_email_body($contact_form) {
$submission = WPCF7_Submission::get_instance();
if ( $submission ) {
/* DEFINE CONSTANT AND GET FPDF CLASSES */
define ('FPDF_PATH',get_template_directory().'/fpdf/'); // MAKE SURE THIS POINTS TO THE DIRECTORY IN YOUR THEME FOLDER THAT HAS FPDF.PHP
require(FPDF_PATH.'fpdf.php');
$posted_data = $submission->get_posted_data();
// SAVE FORM FIELD DATA AS VARIABLES
$name = $posted_data["your-name"];
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Times','B',16);
$pdf->Write(5,$name);
$pdf->Output(FPDF_PATH.'test.pdf', 'F'); // OUTPUT THE NEW PDF INTO THE SAME DIRECTORY DEFINED ABOVE
}
}
add_filter( 'wpcf7_mail_components', 'mycustom_wpcf7_mail_components' );
function mycustom_wpcf7_mail_components($components){
if (empty($components['attachments'])) {
$components['attachments'] = array(FPDF_PATH .'test.pdf'); // ATTACH THE NEW PDF THAT WAS SAVED ABOVE
}
return $components;
}
推荐答案
contact_form){
contact_form) {
submission = WPCF7_Submission :: get_instance();
if (
submission = WPCF7_Submission::get_instance(); if (
submission ){
/ * 定义常数并获取FPDF类* /
define(' FPDF_PATH',get_template_directory()。' / FPDF /'跨度>); // 请确认您的主题文件中的这一点,即FPDF.PHP
require(FPDF_PATH。' fpdf.php');
submission ) { /* DEFINE CONSTANT AND GET FPDF CLASSES */ define ('FPDF_PATH',get_template_directory().'/fpdf/'); // MAKE SURE THIS POINTS TO THE DIRECTORY IN YOUR THEME FOLDER THAT HAS FPDF.PHP require(FPDF_PATH.'fpdf.php');
这篇关于联系表格7和FPDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!