1
Friends,
I have a one-page PHP site that at the bottom of the page has a contact form that submits to the same page.
I wanted after submitting the form to return to the same Action to show the message was sent.
I tried to do that with the redirect with this code below, but it did not work because when redirects it does not show the message.
$redir = '#contact';
header("location:$redir");
Follow the example code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>My Site</title>
<style type="text/css">
*{margin: 0; padding: 0}
#home, #work, #contact{
height: 500px;
border: solid 1px #000;
}
.resultado{
background-color: lightblue;
}
</style>
</head>
<body>
<section id="home">
<p>Home Section</p>
</section>
<section id="work">
<p>Work Section</p>
</section>
<section id="contact">
<div class="resultado">
<?php
if (isset($_POST['nome'])) {
$nome = $_POST['nome'];
echo '<p>Mensagem enviada!</p>';
echo '<p>'.$nome.'</p>';
}
?>
</div>
<form action="index.php" method="post">
<input type="text" name="nome">
<input type="submit" value="Enviar">
</form>
</section>
</body>
</html>