How to insert an HTML file inside a PHP variable?

0

Talk to people,

I have a file named post_forms.php that takes the results of $_POST[] , must fill variables inside the form_xxx.html file, create a PDF with the DomPDF lib and send with PHPMAiler. See a part of each file:

post_forms.php

setlocale(LC_ALL, NULL);
setlocale(LC_ALL, "pt_BR", "pt_BR.iso-8859-1", "pt_BR.utf-8", "portuguese"); 
date_default_timezone_set('America/Bahia');
$data_cadastro = utf8_encode(ucfirst(strftime('%A, %d/%m/%Y, %H:%M:%S')));
$tipo_form = $_POST['tipo-form'];
$protocolo = 'DA'.date("Ymdis");

switch ($tipo_form)
{
    case"Form A":
    ob_start();
    include("forms/form_A.html");;
    $html = ob_get_clean();
    break;
}

echo $html;

$dompdf = new Dompdf();
$dompdf->loadHtml($html);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();

form_A.html

<!DOCTYPE html>
<html lang="pt-br">
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css">
</head>
<body>
    <main>
        <table class="table table-bordered" style="text-align:center;">
            <tr>
                <th rowspan="2" align="center"><img src="img/logo.png"></th>
                <th colspan="4" style="font-size: 1.5em;">FORMULÁRIO - Formulário Tipo A</th>
            </tr>
            <tr>
                <th colspan="2"><strong>$tipo_form</strong> - <big>$protocolo</big></th>
                <th colspan="2"> $data_cadastro</th>
            </tr>
            <tr>
                ...
            </tr>
            <tr>
                ...
            </tr>
            <tr>
                ...
            </tr>
            <tr>
                ...
            </tr>
        </table>
    </main>

    <script> ... </script>
</body>
</html>  

I have no problem with DomPDF classes or PHPMailer, I can generate the pdf and send it by email. What I need to know is, why the PHP variables that are inside the html file are being written with the String containing the name of the variable Ex: $data_cadastro and not being printed the contents of the variable that would be by Ex: Saturday, 08/08/2018, 11:34:00

    
asked by anonymous 08.09.2018 / 16:36

1 answer

1
  

I found the problem, it lacked the tags <?php ?> and the echo call   in the .html

form_A.html

                <th colspan="2"> <?php echo $data_cadastro; ?></th>
    
08.09.2018 / 17:24