Help with step email form

Asked

Viewed 208 times

3

Guys sorry to bother you, I’m creating a 3-step email form with 3 pages and each one is typed data in the input, I’ve already read Section tutorial and I’m not able to print at the end the data of the first and second page to send the email, what I would put on each page to keep the data ?

only the data of the third page that is the last one sent, I would like you to help me, from 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>

1 answer

6


You see, a SESSION may be used by any of its pages, provided that it has a session_start().

The point is, you’re setting a new value for Sesssions on all your pages, so the value that should be passed is reset to the next page. I’ve edited your code and I’m just starting each Sesssion once and recovering on the last page:


PAGE 1

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

<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 and set the SESSIONS correspondent.

<?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 SESSIONS correspondent.

<?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

Recovers the value of all SESSIONS, remembering that I took the value of the variable $msg directly, because it makes no 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, in case you have any questions just ask

Att;

  • Glad I could help, in case you really solved your problem, mark your answer.

  • Thank you very much, I tested here and it worked, is that I am starting now and did not know this rule... ! I was wrong here kkkk aokeoaeokae

  • 1

    I marked here, very good your help, I’m learning little by little!

  • Friend I would like to know how to get everything in the email, because I’m putting to send and it’s coming all the same !

  • Which email? would need to see the part of the code related to the email in order to tell what happens. But if everything is coming it is not correct?

  • is not coming to the email, because instead of printing on the page I put to reach the email... you have email, for me to send you is that I can not post the code here :P

  • no need more friend, thanks for the attention, is that I had forgotten the session_start();

  • @Fleuquerlima in my case I use checkbox and input and select several , how could I make a form in two step ? http://answall.com/questions/180263/como-fazer-formulario-em-etapas

Show 3 more comments

Browser other questions tagged

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