Save fields from one page to another

Asked

Viewed 564 times

0

I have these two pages each with a form, I would like to be able to send in an email the information of the two forms. How do I save field values nome and numero and send only on page 2 along with the other two form fields? I want to avoid sending an email with the page information1 first and then sending another email with the page information2.

Pagina1.html :

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Titulo</title>
</head>
<script type="text/javascript">

</script>
<body>
<form name="form" method="post" action="">
    Nome:
    <input type="text" name="nome">
    Numero:
    <input type="text" name="numero">
    <input type="submit" onclick="window.location.href='pagina2.html';">
</form>

</body>
</html>

Pagina2.html :

<head>
    <meta charset="UTF-8">
    <title>Titulo</title>
</head>
<?php
    $nome = $_POST['nome'];
    ...
?>
<body>
<form name="form" method="post" action="">
    Endereço:
    <input type="text" name="end">
    Bairro:
    <input type="text" name="bairro">
    <input type="submit">
</form>
</body>
</html>

1 answer

1


In this case you would need to GET the data from page 1 to page 2 and save in a Hidden.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Titulo</title>
</head>
<script type="text/javascript">

</script>
<body>
<form name="form" method="get" action="pagina2.html">
    Nome:
    <input type="text" name="nome">
    Numero:
    <input type="text" name="numero">
    <input type="submit">
</form>
</body>
</html>

And on page 2

    <head>
        <meta charset="UTF-8">
        <title>Titulo</title>
    </head>
    <?php
        $nome = $_GET['nome'];
        $numero= $_GET['numero']       
...
    ?>
    <body>
    <form name="form" method="post" action="">
        Endereço:
        <input type="text" name="end">
        Bairro:
        <input type="text" name="bairro">
        <input type="hidden" name="nome" <?php echo "value='$nome'"; ?>>
        <input type="hidden" name="numero" <?php echo "value='$numero'"; ?>>
        <input type="submit">
    </form>
    </body>
    </html>

Then just submit the form 2 and get $_POST["name"] and $_POST["number"] from it, which will be typed in form 1.

Detail: if the page contains PHP, it must have the extension . php

Hugs!

  • At the level of curiosity, there are other ways to do this?

  • 1

    You can do it the way he said, using $_GET, or also $_POST (which would work, but you’d have a problem with the guy updating the page). Another way is by using cookies or Sessions, but if the visitor’s browser does not allow cookies, it will not work. You can also use Javascript so that all fields will be on the same page, and in the same form, then when it passes the first part, the JS hides the fields of the first part and shows the ones of the second part, with this, just make a condition in JS saying that if the visitor is in part 2, the action of the button is to send the form.

Browser other questions tagged

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