문제

I have made a simple form which takes values but now I want to make a pdf of submitted form data when I will click on submit means after submitting the form when used will click on submit then all the form values will be in pdf form. (I want to send that pdf via mail but first I want to understand how to make pdf then I will do that later.)

I have written code for the form and then I use help of fpdf and try to understand the use of its classes.

    <?php
    require('fpdf.php');

    /*$pdf = new FPDF();
    $pdf->AddPage();
    $pdf->SetFont('Arial','B',16);
    $pdf->SetTextColor(50,60,100);
    $pdf->AddPage('P');
    $pdf->SetDisplayMode(real,'default');
    $pdf->Cell(40,10,'Hello World!');
    $pdf->Output();
    */

$labelname = "Membership Form" ;
 include_once 'header.php';?>

I just put those classes in comment or else my membership-form.php will not shown and the blank pdf page will show.

As far I understood that I have to use these functions like addpage, cell and setfont to set the style of pdf, and for putting data I should use this:

function ChapterBody($file)
{
    // Read text file
    $txt = file_get_contents($file);
    // Font
    $this->SetFont('Times','',12);
    // Output text in a 6 cm width column
    $this->MultiCell(60,5,$txt);
    $this->Ln();
    // Mention
    $this->SetFont('','I');
    $this->Cell(0,5,'(end of excerpt)');
    // Go back to first column
    $this->SetCol(0);
}

and this is the part where my mind didn't work as I didn't know about this code. Please tell me how to get data from a form and put in pdf so it will be in pdf after submit.

Here a little part of my form

<table border="0" width="100%;">
<form action="mail_handler.php" method="post">
<tr>
<td>Title</td>
<td>First Name</td>
<td>Middle</td>
<td>Surname</td>
</tr>
<tr>
<td><input type="text" name="title" /> </td>
<td><input type="text" name="fname" /></td>
<td><input type="text" name="middle" /></td>
<td><input type="text" name="surname" /></td>
</tr>

<tr>
<td>Mailing Address</td>
</tr>
<tr>
<td><input type="text" name="email" /></td>
</tr>

<tr>
<td colspan="2">Name of Company / Institution & Address</td>
</tr>
<tr>
<td><input type="text" name="noc" width="30%"/></td>
<td><input type="text" name="noc1" width="30%"/></td>
</tr>

<tr>
<td>Office Tel.</td>
<td>Home Tel.</td>
<td>Mobile No.</td>
<td>E-mail</td>
</tr>
<tr>
<td><input type="text" name="office_no" /> </td>
<td><input type="text" name="Home_no" /></td>
<td><input type="text" name="mobile_no" /></td>
<td><input type="text" name="email" /></td>
</tr>
<tr><td a align="center" colspan="4"><input type="submit" value="submit" name="submit" /></td></tr>
</form>
</table>

I also read this question Sending email filled PDF form but it didn't solve my problem.

도움이 되었습니까?

해결책

After getting a lot searching and negative marks..i did solved my qus..

just edit the mypdf.php

mypdf.php

<?php
include('pdf.php');

if(isset($_POST['submit']) && $_POST['submit']!='' && $_POST['fname']!='')
{
//for mail(i din use it as m wrking offline but hope it will work
/*$to = "xyz@gmail.com"; // this is your Email address
    $from = $_POST['email']; // this is the sender's Email address
    $first_name = $_POST['fname'];
    $last_name = $_POST['surname'];
    $mbile = $_POST['mobile_no'];
    $email = $_POST['email'];
    $subject = "Form submission";
    //$subject2 = "Copy of your form submission";
    $message = $first_name . " " . $last_name . " " . $mbile . " " . $email . "\n\n" . $_POST['message'];
    //$message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];

    $headers = "From:" . $from;
    $headers2 = "From:" . $to;
    mail($to,$subject,$message,$headers);
    //mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
    echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
    // You can also use header('Location: thank_you.php'); to redirect to another page.
    // You cannot use header and echo together. It's one or the other.
*/


       $msg = "title: " .$_POST['title'] . "\n"
            ."fname: " .$_POST['fname'] . "\n"
            ."middle: " .$_POST['mail_add'] . "\n"
            ."surname: " .$_POST['mobile_no'] . "\n"
            ."email: " .$_POST['email'] . "\n"
            ."mail_add: " .$_POST['education'];
        $staffEmail = "staffemail";

    // get your $N value for hear





    $h1_heading = "User Detail";
        $pdf_filename = tempnam(sys_get_temp_dir(), "pdf");
        $pname = explode("\\", $pdf_filename);
        $a=$pname[3];
        $pname1 = explode(".", $a);
        $cname=$pname1[0];//final name for file
        $pdf=new FPDF();
        $pdf->AddPage();
        $pdf->SetFont("Arial", "B", 16);
        $pdf->Cell(40, 10, "User Detail");
        $pdf->Ln();
        $pdf->SetFont("Arial", "", 12);
        $pdf->Cell(40, 10, "First Name:");
        $pdf->SetFont("Arial", "B", 12);
        $pdf->Cell(40, 10, $_POST['fname']);
        $pdf->Ln();
        $pdf->SetFont("Arial", "", 12);
        $pdf->Cell(40, 10, "Address:");
        $pdf->SetFont("Arial", "B", 12);
        $pdf->Cell(40, 10, $_POST['mail_add']);
        $pdf->Ln();
        $pdf->SetFont("Arial", "", 12);
        $pdf->Cell(40, 10, "Mobile No:");
        $pdf->SetFont("Arial", "B", 12);
        $pdf->Cell(40, 10, $_POST['mobile_no']);
        $pdf->Ln();
        $pdf->SetFont("Arial", "", 12);
        $pdf->Cell(40, 10, "E-mail:");
        $pdf->SetFont("Arial", "B", 12);
        $pdf->Cell(40, 10, $_POST['email']);
        $pdf->Ln();
        $pdf->SetFont("Arial", "", 12);
        $pdf->Cell(40, 10, "Education:");
        $pdf->SetFont("Arial", "B", 12);
        $pdf->Cell(40, 10, $_POST['education']);
        $a=$_POST['mobile_no'];
        $pdf->output("pdf/". "$a" .$cname.".pdf" , 'f');
        $pdf->Ln(45);
        header("Location:index.php");
}
else
{
header("Location:membership-form.php");
}

?>

다른 팁

For reference:

You can use MPDF lib to generate PDF. In it you just need to pass your HTML content.

For Email send and attachment PHP Mailer

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top