0
I wanted to keep the form data, after giving a Submit on the page. There is no way even?
0
I wanted to keep the form data, after giving a Submit on the page. There is no way even?
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 php javascript html5
You are not signed in. Login or sign up in order to post.
exists and already has answer here on the site. I will look for the link...
– Bacco
Oops, if you find me, I haven’t found it yet.
– Alisson Hoepers
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– Bacco
But I have to initialize the variable with null, right?
– Alisson Hoepers
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.– Bacco
however I will pass more data, beyond the name and I will play to a function that will bring a result of the database.
– Alisson Hoepers
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– Bacco