No way to keep input data after Ubmit?

Asked

Viewed 608 times

0

I wanted to keep the form data, after giving a Submit on the page. There is no way even?

  • 1

    exists and already has answer here on the site. I will look for the link...

  • Oops, if you find me, I haven’t found it yet.

  • 1

    Normally, if it’s PHP and normal Submit, you can do this $nome = isset( $_POST['nome'] )?$_POST['nome']:''; and in the form <input name ="nome" value="<?php echo htmlentities( $nome ); ?>">, as long as you send $_POST to the same page that generates the form

  • But I have to initialize the variable with null, right?

  • No need, see that the ternary of isset is already returning empty if you don’t have the post. Take advantage that there is no answer, click [Edit] and put your code in part PHP and HTML, which makes it easier to post an example.

  • however I will pass more data, beyond the name and I will play to a function that will bring a result of the database.

  • Anyway, you have to [Edit] explain the flow of data and preferably by a minimum example of code the way you are doing now, to facilitate who is to give answers. The essence is what I put in the comment, which is to fill the value with the information, regardless of where the data comes from

Show 2 more comments

1 answer

0


<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <form action="" method="POST" >
            <?php
              $user = (!empty($_POST['user'])) ? $_POST['user'] : '';
             ?> 
            <input type="text" name="user" id="user" value="<?php echo htmlentities( $user ) ; ?>" />
            <input type="submit" value="Enviar" />
        </form>

    </body>
</html>

Browser other questions tagged

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