I want to clear the input values when the form is submitted correctly, But there is a problem, if not inserted, the inputs are erased. I will be grateful for help me. This is my code:
$(document).ready(function(){
$("#Insert").click(function(){
var email = $("#email").val();
var title = $("title").val();
var text = $("text").val();
var cSend = true;
$.post("ajax.php",{email:email,title:title,text:text,cSend:cSend},function(data){
$("#contactResualt").html(data);
});
});
});
//ajax.php
if(isset($_POST['cSend'])){
if (empty($_POST['email']) || empty($_POST['title']) || empty($_POST['text'])){
echo '<div class="alert alert-warning">Fill empty fields</div>';
}
else{
$email = $_POST['email'];
$title = $_POST['title'];
$text = $_POST['text'];
$Contactus = new Contactus();
$resualt = $Contactus->SendPM($email,$title,$text);
if($resualt){
echo '<div class="alert alert-success">Insertion was successful</div>';
}
else{
echo '<div class="alert alert-warning">Insertion failed</div>';
}
}
}
So, I just want the information to be correctly inserted, Inputs will be cleared.