【发布时间】:2020-11-22 10:06:57
【问题描述】:
我正在尝试使用 FPDF 从 html 表单创建 PDF。
一切都很顺利,除了一组复选框:
HTML:
<div class="form-group checkboxes" required>
<p>Que aulas pretende frequentar?</p><span class="clue"> (Selecione as opções aplicáveis)</span></p>
<label for="pre-ballet">
<input
name="aulas[]"
id="pre-ballet"
type="checkbox"
value="pre-ballet"
/><span> Pre-Ballet/ Dança Criativa - 3 aos 6 anos</span></label>
<label for="classic">
<input
name="aulas[]"
id="classic"
type="checkbox"
value="classic"
/><span> Técnica de Dança Clássica - Primary/ Iniciantes - 6 aos 9 anos / 10 aos 12 anos / mais de 12 anos</span></label>
<label for="contemporary">
<input
name="aulas[]"
id="contemporary"
type="checkbox"
value="contemporary"
/><span> Técnica de Dança Contemporânea - 8 aos 14 anos / mais de 14 anos</span></label></div>
PHP:
if(isset($_POST['sendemail']))
{
require('C:\Users\mcane\scoop\apps\apache\2.4.43\htdocs\PHP\vendor\fpdf\fpdf.php');
$title = 'Inscrição';
$name = $_POST['name'];
$email_id = $_POST['email'];
$age = $_POST['age'];
$aulas = $_POST['aulas'];
// create PDF
$pdf = new FPDF();
$pdf -> AddPage();
$pdf->SetTitle($title);
// Arial bold 15
$pdf->SetFont('Arial','B',15);
// Calculate width of title and position
$w = $pdf->GetStringWidth($title)+6;
$pdf->SetX((210-$w)/2);
// Colors of frame, background and text
$pdf->SetDrawColor(221,221,221,1);
$pdf->SetFillColor(10,158,0,1);
$pdf->SetTextColor(255,255,255,1);
// Thickness of frame (1 mm)
$pdf->SetLineWidth(1);
// Title
// Cell(width, height, content, border, nextline parametters, alignement[c - center], fill)
$pdf->Cell($w, 9, $title, 1, 1, 'C', true);
// Line break
$pdf->Ln(10);
$pdf->SetTextColor(0,0,0,1);
$w = $pdf->GetStringWidth($name)+30;
$pdf->SetX((170-$w)/2);
$pdf->Cell(40, 10, 'Nome:', 1, 0, 'C');
$pdf->Cell($w, 10, $name, 1, 1, 'C');
$pdf->SetX((170-$w)/2);
$pdf->Cell(40, 10, 'Email:', 1, 0, 'C');
$pdf->Cell($w, 10, $email_id, 1, 1, 'C');
$pdf->SetX((170-$w)/2);
$pdf->Cell(40, 10, 'Idade:', 1, 0, 'C');
$pdf->Cell($w, 10, $age, 1, 1, 'C');
$pdf->SetX((170-$w)/2);
$pdf->Cell(40, 10, 'Aulas:', 1, 0, 'C');
$pdf->Cell($w, 10, $aulas, 1, 1, 'C');
当我提交表单时,会生成 PDF,但我收到此错误消息 - 警告:iconv() 期望参数 3 是字符串,C:... 中给出的数组 - 并且“aulas”单元格为空.
有人可以帮帮我吗?
最好的问候。
【问题讨论】: