I have a website where any visitor can subscribe to receive the newsletter.I encountered the problem of having my resubmitted when everytime when i refreshed the page.I solved it by applying the PRG concept. Now a user never submits the same form twice, i have just one problem : i have designed the form in such a way that when the is succesfully/or fails a message is display under the input fields. Unfortunatly now that i have the PRG concept applied i never get any message displayed . What to do ?
index.php - where i have the divs containing the submit form and the message display
<div id="newsletter" >
<form id="abonat" name="abonat" action="formular.php" method="post" onsubmit="return golire()" autocomplete="on" >
<span>Subscribe</span>
<input type="text" id="nume" name="nume" placeholder="Name" required />
<input type="email" id="email" name="email" placeholder="Email" autocomplete="off" required/>
<input type="submit" value="Subscribe" class="button" style="width:26%;float:left;" />
</form>
</div>
<div id="mesaj_newsletter">
<span><?php if (isset($mesaj)) echo $mesaj; ?> </span>
</div>
formular.php - where the validation takes place,and the message is decided
include('conect.php');
function validEmail($email){
//code that verifies if it is a valid email adress
}
if( (isset($_POST['email']))&&(isset($_POST['nume'])) ){
$nume=mysql_real_escape_string($_POST['nume']);
$email=mysql_real_escape_string($_POST['email']);
$z=1;
if(validEmail($email)==TRUE){
$result=mysql_query("SELECT * FROM abonat");
while($data=mysql_fetch_row($result)){
if(($data[1]==$email)||($data[2]==$nume))
$z=0;
}
if($z==1){
mysql_query("INSERT INTO abonat(email,nume) VALUES ('$email','$nume')");
$mesaj="Your email has been registered";
}
else $mesaj="You are already registered";
}
else $mesaj="You have not entered a valid email adress";
}
mysql_close($con);
header('Location:index.php');
?>