Send data to a pdf and email file

Asked

Viewed 28 times

0

Good afternoon I would like to save data from a form of an html page when users register and commit in a pdf file and be sent to a predefined email but I do not know how to do this, I have the form created as follows:

    <!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Formulário</title>
</head>
<body>
 <h2> Preencha o formulário abaixo para participar no curso de Linux Administração</h2><br/>

<form action="Script_do_Formulario.php" method="post">

<!-- DADOS PESSOAIS-->
<fieldset>
 <legend>Dados Pessoais</legend>
 <table cellspacing="10">
  <tr>
   <td>
    <label for="nome">Nome: </label>
   </td>
   <td align="left">
    <input type="text" name="email">
   </td>
   <td>
    <label for="sobrenome">Apelido: </label>
   </td>
   <td align="left">
    <input type="text" name="sobrenome">
   </td>
  </tr>
  <tr>
   <td>
    <label>Data de Nascimento: </label>
   </td>
   <td align="left">
    <input type="text" name="dia" size="4" maxlength="2" value="dd"> 
   <input type="text" name="mes" size="6" maxlength="2" value="mm"> 
   <input type="text" name="ano" size="8" maxlength="4" value="aaaa">
   </td>
  </tr>
  <tr>
   <td>
    <label for="rg">Localidade: </label>
   </td>
   <td align="left">
    <input type="text" name="rg" size="13" maxlength="13"> 
   </td>
  </tr>
  <tr>
   <td>
    <label>Código Postal:</label>
   </td>
   <td align="left">
    <input type="text" name="cpf" size="9" maxlength="9"> - <input type="text" name="cpf2" size="2" maxlength="2">
   </td>
  </tr>
 </table>
</fieldset>

<br />
<!-- ENDEREÇO -->
<fieldset>
 <legend>Morada</legend>
 <table cellspacing="10">

  <tr>
   <td>
    <label for="rua">Rua:</label>
   </td>
   <td align="left">
    <input type="text" name="rua">
   </td>
   <td>
    <label for="numero">Numero:</label>
   </td>
   <td align="left">
    <input type="text" name="numero" size="4">
   </td>
  </tr>
  <tr>
   <td>
    <label for="bairro">Localidade: </label>
   </td>
   <td align="left">
    <input type="text" name="bairro">
   </td>
  </tr>
  <tr>
   <td>
    <label for="estado">Distrito:</label>
   </td>
   <td align="left">
    <select name="estado"> 
    <option value="av">Aveiro</option> 
    <option value="be">Beja</option> 
    <option value="br">Braga</option> 
    <option value="bg">Bragança</option> 
    <option value="cb">Castelo Branco</option> 
    <option value="cm">Coimbra</option> 
    <option value="ev">Évora</option> 
    <option value="fr">Faro</option> 
    <option value="gd">Guarda</option> 
    <option value="lr">Leiria</option> 
    <option value="lx">Lisboa</option> 
    <option value="Pg">Portalegre</option> 
    <option value="pt">Porto</option> 
    <option value="st">Santarém</option> 
    <option value="sb">Setúbal</option> 
    <option value="vc">Viana do Castelo</option> 
    <option value="vr">Vila Real</option> 
    <option value="vs">Viseu</option> 
    <option value="im">Ilha da Madeira</option> 
    <option value="ia">Ilha dos Açores</option> 
    </select>
   </td>
  </tr>
  <tr>
   <td>
    <label for="cidade">Cidade: </label>
   </td>
   <td align="left">
    <input type="text" name="cidade">
   </td>
  </tr>
  <tr>
   <td>
    <label for="cep">Código Postal: </label>
   </td>
   <td align="left">
    <input type="text" name="cp" size="3" maxlength="4"> - <input type="text" name="cp2" size="2" maxlength="3">
   </td>
  </tr>
 </table>
</fieldset>
<br />

<!-- DADOS DE LOGIN -->
<fieldset>
 <legend>Contacto Email</legend>
 <table cellspacing="10">
  <tr>
   <td>
    <label for="email">E-mail: </label>
   </td>
   <td align="left">
    <input type="text" name="email">
   </td>
  </tr>
  </table>
</fieldset>
<br />
<input type="submit">
<input type="reset" value="Limpar">
</form>
</body>
</html>

1 answer

0

Only using HTML you won’t be able to do it so easy (there are Javascript libraries that could take care of this paete) but something simple to implement, but requiring an email client installed and configured on the user’s computer, is simply to:

<form action="mailto:«conta de e-mail»" method="get">
   ...
</form>

Then the form data will be sent to the e-mail address indicated on the form.

But I also saw that your form, at first, would send the data to a program in PHP, the "Script_do_formulario.php", in this case your doubt would also be in this language?

So a very simple program to receive and send the form data to a specific email address would look something like this:

<?php
    /* lê os campos via POST */
    $nome = $_POST['nome'];
    ...

    /* alguma validação */
    ...

    /* monta a mensagem */
    $mensagem = "Ficha de Inscrição\n".
        "- - - - - - - - - - - - - - - - - - - -\n".
        "Nome : ".$nome."\n".
        "- - - - - - - - - - - - - - - - - - - -\n";

    mail('[email protected]','Ficha de Inscrição', $mensagem);
?>

Of course, this program recovers only "name" of the form (it is possible to perceive the logic to do the same with the other fields) and assembles the body of a message to be sent by the mail() function of PHP itself.

  • Yes, because I never programmed in PHP

  • Add the php tag to your question.

  • where exactly do I tag 'php' in my code? I wonder why I don’t understand where

Browser other questions tagged

You are not signed in. Login or sign up in order to post.