How can I insert a $_POST
into a input
of a HTML
form?
In a simple login form, by leaving a field blank, the script retrieves the filled field, keeps it filled, and reports the error of the empty field, so the user does not have to type again.
Is there a way to do this with PHP
, without Javascript
?
Basically the script would receive the $_POST
sent and fill the respective field.
Only the same insertion script is missing.
<?php
function checkUsername($username)
{
if ($username == "")
{
echo "<span style='color:red'>Preencha o campo Username!</span><br>";
}
}
function checkPassword($password)
{
if ($password == "")
{
echo "<span style='color:red'>Preencha o campo Password!</span><br>";
}
}
<?php
include 'includes/functions.php';
$check = false;
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
checkUsername($_POST['username']);
checkPassword($_POST['password']);
$check = true;
}
?>
<!-- FORMULÁRIO DE LOGIN -->
<div id="form">
<form action="" method="post">
<div class="_100">
<label for="username">Username: </label><br>
<input type="text" name="username" placeholder="Username"><br>
</div>
<div class="">
<label for="password">Password: </label><br>
<input type="password" name="password" placeholder="*******"><br>
</div>
<br>
<div class="">
<input type="submit" value="Entrar no Sistema">
</div>
</form>
</div>
<!-- /FORMULÁRIO DE LOGIN -->