2010-11-10 43 views

回答

0

我還沒有完成WP插件的詳盡搜索,但從我可以告訴答案是否定的。當然,從零開始創建這樣一個插件是可能的,但是託管WP的服務器需要安裝正確的庫以使插件有用。

+0

http://wordpress.stackexchange.com/questions/3895/submit-to-pdf-in-wordpress – serhio 2010-11-10 20:26:29

1

我發現這些插件允許發佈郵件或下載爲PDF文件。

http://wordpress.org/extend/plugins/tags/create-pdf

如果你是靈活的,這似乎可以以編程方式創建的帖子從用戶提交表單,然後創建後的PDF文件。從表單創建的帖子可以很容易地分配給一個特定的類別,該類別不會在網站上顯示。

以編程方式創建,更新和刪除帖子,看到WordPress的功能參考,特別是:

wp_insert_post wp update post wp delete post

快速google search展品很多的方法來創建PDF文件用PHP。有些困難,有些困難。 I found this class that might get you started: "FPDF"

4

如果你想填寫表格,然後處理該表格的細節並通過電子郵件發送給你,並附上詳細的pdf附件,幾周前我有類似的東西,我找不到任何可以工作的東西我想要的方式,所以...

我設置我的表單,然後使用自定義頁面模板,我分配到一個頁面,然後使用PHP和html2pdf class我創建了我的PDF格式,通過電子郵件發送附件...

繼承人的代碼,我用.. 作壓縮此頁面(記得要淨化你的用戶輸入)。

<?php 
/* 
Template Name: FORMTOPDF 
*/ 
?> 
<?php get_header(); ?> 
<style> 
/* STYLES FOR ERROR PLACEMENT */ 
label { 
    width: 80px; 
    text-align: right; 
    float: left; 
} 
.formerror { 
    border: 1px solid red; 
    background-color : #FFCCCC; 
    width: auto; 
    padding: 5px 0; 
    padding-left:10px; 
} 
.errortext { 
    font: bold smaller sans-serif; 
} 
</style> 
<?php 
// CREATE AN ARRAY FOR OUR ERRORS 
$arrErrors = array(); 
// Check for FORM SUBMISSION 
// using hidden form field 
if(isset($_POST['action']) && ($_POST['action']=='send')) 
{ 
/* ================= START FORM DATA ========================= */ 
    $name = trim($_POST['name']); 
    if ($name=='') $arrErrors['name'] = 'Please provide your name.'; 

    $email = trim($_POST['email']); 
    if ($email=='') $arrErrors['Email'] = 'Please provide your Email Address.'; 

    $comments = trim($_POST['your-comments']); 
    if ($comments=='') $arrErrors['Comments'] = 'Please add your Comments.'; 
/* ================= END FORM DATA ========================= */ 

    if (count($arrErrors) == 0) { 
     // Process form here 
    /* ================= START PDF CREATION ========================= */ 
    $strContent = "<p>Submission from ".$name."</p>"; 
    $strContent.= "<p><strong>Name</strong>:".$name."</p>"; 
    $strContent.= "<p><strong>Email </strong>: ".$email."</p>"; 
    $strContent.= "<p><strong>Comments</strong> : <br />".$comments."</p>"; 
    /* ================= END PDF CREATION ========================= */ 
    // Include our HTML to PDF creator 
    // FROM THEME DIRECTORY? 
    require(TEMPLATEPATH.'/html2pdf/html2fpdf.php'); 
    $pdf=new HTML2FPDF(); 
    $pdf->AddPage(); 
    // folder location of HTML file 
    $fileLocation = "wp-content/uploads/"; 
    // Call to the file name from the URL 
    $fileName = "Form_Submission_From_".$name; 
    // add the location 'wp-content/uploads/' to the fileToOpen 
    $fileToOpen = $fileLocation; 
    // Then add the actual file name // form_submission.pdf 
    // output should look like 'wp-content/uploads/form_submission_from_(name).pdf' 
    $fileToOpen .= $fileName.".pdf"; 
    // Open the file with read access 
    $fp = fopen($fileToOpen,"r"); 
    //$strContent = fread($fp, filesize($fileToOpen)); 
    // Close of the page 
    fclose($fp); 
    // Create new PDF document from the Content 
    $pdf->WriteHTML($strContent); 
    // create our PDF in the wp uploads folder 
    $pdf->Output("wp-content/uploads/" .$fileName. ".pdf"); 
    /* ================= END PDF ========================= */ 

    /* ================= START EMAIL ========================= */ 
    $headers= "From: YourWebsite <[email protected]>\r\n\\"; 
    $emailSubject = "Submission from " . $name; 
    $emailAdmin = "[email protected]"; 
    $emailMessage = "Submission from ".$yourcompanyname."\n\n"; 
    $emailMessage.= "Company Name: ".$yourcompanyname."\n"; 
    $emailMessage.= "Email : ".$email."\n"; 
    $emailMessage.= "Comments : \n".$comments."\n\n"; 
    $attachments = array(WP_CONTENT_DIR ."/uploads/".$fileName.".pdf", $target_path); 
    wp_mail($emailAdmin, $emailSubject, $emailMessage, $headers, $attachments); 

    // Delete our PDF from the server after email Sent 
    // uncomment this to delete after email sent? 
    //unlink($fileToOpen); 
    /* ================= END EMAIL ========================= */ 

    // show thank you message if successful 
    $strGood = '<div class="formerror" style="background:#FFC;"> 
    <h2>Thank You</h2> 
    <p>Thank you for contacting us.</p> 
    </div>'; 


    }else{ 

    // The error array had something in it. There was an error. 
    // Start adding error text to an error string. 
    $strError = '<div class="formerror"><p><img style="margin-left:10px;" src="'.get_option('home').'/wp-content/themes/mytheme/media/images/triangle_error.gif" width="16" height="16" hspace="5" alt=""><strong>Please check the following and try again:</strong></p><ul style="margin-left:50px;">'; 

    // Get each error and add it to the error string 
    // as a list item. 
    foreach ($arrErrors as $error) { 
     $strError .= "<li style='list-style-type:circle;'><em>$error</em></li>"; 
    } 
    $strError .= '</ul></div><br />'; 
    } 
}// NOT BEEN SUBMITTED 
// show regular page with form 
?> 
<?php if (have_posts()) : while (have_posts()) : the_post(); ?> 
<div class="post" id="post-<?php the_ID(); ?>"> 
<h2> 
<?php the_title(); ?> 
</h2> 
<?php 
// show errors if there is any 
echo $strError; 
?> 
<?php 
// show thank you if successful 
echo $strGood; 
?> 
<?php the_content('<p>Read the rest of this page &raquo;</p>'); ?> 
<form method="post" action="<?php bloginfo('url');?>/your-form-page/" enctype="multipart/form-data"> 
<input type="hidden" value="send" name="action"> 
<p <?php if (!empty($arrErrors['name'])) echo ' class="formerror"'; ?>>Your Name: 
<span class="errortext" style="color:#F00;">(required)</span><br> 
The rest of the form below here ------ > 
</form> 
<?php endwhile; endif; ?> 
<?php get_footer(); ?> 

完蛋了,一旦用戶填寫表單,(我的形式有比這多很多領域外加文件上傳領域也附後。)

但形式提交,支票對於必填字段,如果成功,它將從$ strContent變量創建一個pdf文件,然後將其附加到使用wordpress中的wp_mail發送的電子郵件中,然後顯示一條感謝消息,否則它將顯示並突出顯示任何錯誤,

希望這有助於...