Help with e-mail form in steps

3

I'm sorry for the inconvenience, I'm creating a 3-page email form with 3 pages and each one is typed in the input, I've already read the session tutorial and I'm not able to print the first and second page data at the end. send the email, what would I put on each page to keep the data?

Only the data of the third page that is the last one is being sent, I would like you to help me, right now, thank you!

PAGINA 1

<?php
session_start();

$nome = isset($_POST['nome']) ? $_POST['nome'] : '';
$_SESSION['nome'] = $nome;

$email = isset($_POST['email']) ? $_POST['email'] : '';
$_SESSION['conta'] = $conta;

$telefone = isset($_POST['telefone']) ? $_POST['telefone'] : '';
$_SESSION['telefone'] = $telefone;

?>
<html>

<form method="POST" action="index2.php">
  <label>Nome</label>
  <input type="text" name="nome" maxlength="50" />
   <label>Email</label>
  <input type="text" name="email" maxlength="50" />
 
  <label>Telefone</label>
  <input type="text" name="telefone" maxlength="50" />
 
  <input type="submit" value="Submit" name="Proximo">
</form>

</html>


////

PAGINA 2

<?php
session_start();

$nome = isset($_POST['nome']) ? $_POST['nome'] : '';
$_SESSION['nome'] = $nome;

$email = isset($_POST['email']) ? $_POST['email'] : '';
$_SESSION['conta'] = $conta;

$telefone = isset($_POST['telefone']) ? $_POST['telefone'] : '';
$_SESSION['telefone'] = $telefone;

$cidade = isset($_POST['cidade']) ? $_POST['cidade'] : '';
$_SESSION['cidade'] = $cidade;

$estado = isset($_POST['estado']) ? $_POST['estado'] : '';
$_SESSION['estado'] = $estado;

?>
<html>
<form method="post" action="index3.php">
 <label>Cidade</label>
  <input type="text" name="cidade" maxlength="50" />
  <label>Estado</label>
  <input type="text" name="estado" maxlength="50" />
  <input type="submit" value="Submit" name="Proximo">
</html>

//

PAGINA 3

<?php
session_start();

$nome = isset($_POST['nome']) ? $_POST['nome'] : '';
$_SESSION['nome'] = $nome;

$email = isset($_POST['email']) ? $_POST['email'] : '';
$_SESSION['conta'] = $conta;

$telefone = isset($_POST['telefone']) ? $_POST['telefone'] : '';
$_SESSION['telefone'] = $telefone;

$cidade = isset($_POST['cidade']) ? $_POST['cidade'] : '';
$_SESSION['cidade'] = $cidade;

$estado = isset($_POST['estado']) ? $_POST['estado'] : '';
$_SESSION['estado'] = $estado;

$msg = isset($_POST['msg']) ? $_POST['msg'] : '';
$_SESSION['msg'] = $msg;

?>
<html>
<form method="post" action="final.php">
 <label>Mensagem</label>
  <input type="text" name="msg" maxlength="50" />
  <input type="submit" value="Submit" name="Enviar">
</html>


PAGINA 4


<?php
session_start();

$nome = isset($_POST['nome']) ? $_POST['nome'] : '';
$_SESSION['nome'] = $nome;

$email = isset($_POST['email']) ? $_POST['email'] : '';
$_SESSION['email'] = $email;

$telefone = isset($_POST['telefone']) ? $_POST['telefone'] : '';
$_SESSION['telefone'] = $telefone;

$cidade = isset($_POST['cidade']) ? $_POST['cidade'] : '';
$_SESSION['cidade'] = $cidade;

$estado = isset($_POST['estado']) ? $_POST['estado'] : '';
$_SESSION['estado'] = $estado;

$msg = isset($_POST['msg']) ? $_POST['msg'] : '';
$_SESSION['msg'] = $msg;

?>

<html>
 <label>nome: <?php echo "$nome"; ?> </label>
  <label>email: <?php echo "$email"; ?> </label>
   <label>telefone: <?php echo "$telefone"; ?> </label>
    <label>cidade: <?php echo "$cidade"; ?> </label>
     <label>estado: <?php echo "$estado"; ?> </label>
   <label>mensagem: <?php echo "$msg"; ?> </label>
</html>
    
asked by anonymous 22.06.2016 / 17:47

1 answer

6

You see, a SESSION can be used by any of your pages, as long as it has session_start() .

The point is, you are setting a new value for the sessions on all your pages, so the value that should be passed is zeroed on the next page. I edited your code and I'm just starting each session once and retrieving on the last page:

PAGE 1

This page does not need SESSION , it just creates the form and sends it to the next one.

<html>
    <form method="POST" action="index2.php">
        <label>Nome</label>
        <input type="text" name="nome" maxlength="50" />

        <label>Email</label>
        <input type="text" name="email" maxlength="50" />

        <label>Telefone</label>
        <input type="text" name="telefone" maxlength="50" />

        <input type="submit" value="Submit" name="Proximo">
    </form>
</html>

PAGE 2

This page should take the data started in the first one and set the SESSIONS corresponding.

<?php

session_start();

$nome = isset($_POST['nome']) ? $_POST['nome'] : '';
$_SESSION['nome'] = $nome;

$email = isset($_POST['email']) ? $_POST['email'] : '';
$_SESSION['email'] = $email;

$telefone = isset($_POST['telefone']) ? $_POST['telefone'] : '';
$_SESSION['telefone'] = $telefone;

?>

<html>
    <form method="post" action="index3.php">
        <label>Cidade</label>
        <input type="text" name="cidade" maxlength="50" />

        <label>Estado</label>
        <input type="text" name="estado" maxlength="50" />

        <input type="submit" value="Submit" name="Proximo">
    </form>
</html>

PAGE 3

This page should take the data started and received from the second and set the corresponding SESSIONS .

<?php

session_start();

$cidade = isset($_POST['cidade']) ? $_POST['cidade'] : '';
$_SESSION['cidade'] = $cidade;

$estado = isset($_POST['estado']) ? $_POST['estado'] : '';
$_SESSION['estado'] = $estado;

?>

<html>
    <form method="post" action="final.php">
        <label>Mensagem</label>
        <input type="text" name="msg" maxlength="50" />

        <input type="submit" value="Submit" name="Enviar">
    </form>
</html>

PAGE 4

Retrieve the value of all SESSIONS , remembering that I got the value of the variable $msg directly, since it does not make sense to start a SESSION to use its value on the page itself.

<?php

session_start();

$nome = $_SESSION['nome'];
$email = $_SESSION['email'];
$telefone = $_SESSION['telefone'];
$cidade = $_SESSION['cidade'];
$estado = $_SESSION['estado'];
$msg = isset($_POST['msg']) ? $_POST['msg'] : '';

?>

<html>
    <label>nome: <?php echo "$nome"; ?> </label>
    <label>email: <?php echo "$email"; ?> </label>
    <label>telefone: <?php echo "$telefone"; ?> </label>
    <label>cidade: <?php echo "$cidade"; ?> </label>
    <label>estado: <?php echo "$estado"; ?> </label>
    <label>mensagem: <?php echo "$msg"; ?> </label>
</html>

Well that's it, if you have any questions just ask

Att;

    
22.06.2016 / 18:08