Exporting form results from Contact form 7 to PDF (fPDF)

Asked
Active3 hr before
Viewed126 times

5 Answers

contactresults
90%

I needed to accomplish the same thing and finally got the Contact Form 7 results to be converted to a PDF. I ended up using a combination of suggestions mentioned in a few forums, this one included.,How can I pull the content from Contact form 7? Now if I press send I only get a PDF with "first name" written on it. I've tried multiple combinations, nothing works.,I am trying to export the values that users input into Contact form 7 in WordPress, to PDF via fpdf. This is what I've set up, I can generate a PDF but without the dynamically generated value from the form.,EDIT: I have figured out how to print, but it seems like the problem is, that I am not pulling the inserted content from Contact Form 7.

the solution above by Kory works perfectly. However, it doesn't work with radio buttons. All of the radio buttons are only displaying as "Array" on the final PDF. How do I display the radio button choices properly? The code I'm using is below. Thanks!

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_stylesheet_directory().
         '/fpdf17/'); // 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"];
      $name2 = $posted_data["your-name2"];
      $email = $posted_data["your-email"];
      $enhetsnr = $posted_data["number-363"];
      $radio220 = $posted_data["radio-220"];
      $radio221 = $posted_data["radio-221"];
      $radio222 = $posted_data["radio-222"];
      $radio223 = $posted_data["radio-223"];
      $radio224 = $posted_data["radio-224"];
      $radio225 = $posted_data["radio-225"];

      $pdf = new FPDF('P', 'mm', 'A4');
      $pdf - > AddPage();
      $pdf - > SetFont('Times', '', 16);
      $pdf - > Write(5, $name.
         "\n\n".$name2.
         "\n\n".$email.
         "\n\n".$enhetsnr.
         "\n\n".$radio220.
         "\n\n".$radio221.
         "\n\n".$radio222.
         "\n\n".$radio223.
         "\n\n".$radio224.
         "\n\n".$radio225);
      $pdf - > Output(FPDF_PATH.
         'tillval.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.
         'tillval.pdf'); // ATTACH THE NEW PDF THAT WAS SAVED ABOVE
   }
   return $components;
}
load more v
88%

If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.,Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question. ,Application Lifecycle> Running a Business Sales / Marketing Collaboration / Beta Testing Work Issues , communitylounge Who's Who Most Valuable Professionals The Lounge   The CodeProject Blog Where I Am: Member Photos The Insider News The Weird & The Wonderful

define('FPDF_FONTPATH', get_template_directory().
   'fpdf/font/');
define('FPDF_PATH', get_template_directory().
   '/fpdf/');
require(FPDF_PATH.
   'fpdf.php');
load more v
72%

How to remove form validation errors when the fields are generated with localstorage data , How to use auto increment field in insert for CI 3 ,I’m trying to export the results from a cf7 form to pdf using FPDF. The solution posted here works great for text fields. However, it doesn’t work with radio buttons. All of the radio buttons are only displaying as “Array” on the final PDF. How do I display the radio button choices properly? The code I’m using is below. Thanks!, PHP Get number of Sat&Sun for each month between two dates

I’m trying to export the results from a cf7 form to pdf using FPDF. The solution posted here works great for text fields. However, it doesn’t work with radio buttons. All of the radio buttons are only displaying as “Array” on the final PDF. How do I display the radio button choices properly? The code I’m using is below. Thanks!

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_stylesheet_directory().
         '/fpdf17/'); // 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"];
      $name2 = $posted_data["your-name2"];
      $email = $posted_data["your-email"];
      $enhetsnr = $posted_data["number-363"];
      $radio220 = $posted_data["radio-220"];
      $radio221 = $posted_data["radio-221"];
      $radio222 = $posted_data["radio-222"];
      $radio223 = $posted_data["radio-223"];
      $radio224 = $posted_data["radio-224"];
      $radio225 = $posted_data["radio-225"];

      $pdf = new FPDF('P', 'mm', 'A4');
      $pdf - > AddPage();
      $pdf - > SetFont('Times', '', 16);
      $pdf - > Write(5, $name.
         "\n\n".$name2.
         "\n\n".$email.
         "\n\n".$enhetsnr.
         "\n\n".$radio220.
         "\n\n".$radio221.
         "\n\n".$radio222.
         "\n\n".$radio223.
         "\n\n".$radio224.
         "\n\n".$radio225);
      $pdf - > Output(FPDF_PATH.
         'tillval.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.
         'tillval.pdf'); // ATTACH THE NEW PDF THAT WAS SAVED ABOVE
   }
   return $components;
}
65%

What I have learned is that the screen shot method is not really possible. So what I have done is used a method prescribed here using FPDF: https://wordpress.org/support/topic/convert-pdf-file,Connect and share knowledge within a single location that is structured and easy to search., Why are we to leave a front-loader clothes washer open, but not the dishwasher? ,If not, how can I get this done? What may be the steps?

0
75%

To create a pdf from a form using php. In this tutorial, you will learn how generate a pdf file using fpdf in php.,In this tutorial, you have learned how to create PDF file in PHP using fpdf.,So, this tutorial will guide you step by step on how to create pdf file using the fpdf in php.,The pdf.php file code will create pdf file using fpdf library.

<!DOCTYPE html>
<html lang="en">

<head>
   <meta charset="UTF-8">
   <title>Simple Registration Form in PHP - Tutsmake.com</title>
   <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
   <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
   <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
   <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"></script>
   <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
</head>

<body>
   <div class="container">
      <div class="row">
         <div class="col-lg-8 col-offset-2">
            <div class="page-header">
               <h2>Registration Form in PHP</h2>
            </div>
            <p>Please fill all fields in the form</p>
            <form action="pdf.php" method="post">

               <div class="form-group">
                  <label>Name</label>
                  <input type="text" name="name" class="form-control" value="" maxlength="50" required="">
               </div>

               <div class="form-group ">
                  <label>Email</label>
                  <input type="email" name="email" class="form-control" value="" maxlength="30" required="">
               </div>

               <div class="form-group">
                  <label>Mobile</label>
                  <input type="text" name="mobile" class="form-control" value="" maxlength="12" required="">
                  <span class="text-danger">
               </div>

               <input type="submit" class="btn btn-primary" name="signup" value="submit">
            </form>
         </div>
      </div>
   </div>
</body>

</html>
load more v

Other "contact-results" queries related to "Exporting form results from Contact form 7 to PDF (fPDF)"