Skip to content

Instantly share code, notes, and snippets.

@Anan5a
Created November 12, 2016 14:46
Show Gist options
  • Save Anan5a/55032418678010a7136fadfe1ab75f26 to your computer and use it in GitHub Desktop.
Save Anan5a/55032418678010a7136fadfe1ab75f26 to your computer and use it in GitHub Desktop.
$(document).ready(function(){
//ajax form
$('#submit').click(function(e){
e.preventDefault();
$(this).text('Sending...');
//$(this).prop('disabled',false);
console.log('Clicked');
var
fname=$('#fname').val(),
lname=$('#lname').val(),
_message=$('#message').val(),
sub=$('#subject').val(),
email=$('#email').val(),
dropdown1;
$('select').change(function(){
dropdown1=$(this).val();
});
var gcaptcha;
/*if(grecaptcha!='undefined'){
gcaptcha=grecaptcha.getResponse();
} */
$.ajax(console.log('ajax'),{
type:"POST",
url:'handle.php',
data:{
submit:'ok',
fn:fname,
__dep:dropdown1,
ln:lname,
email:email,
message:_message,
subject:sub
},
success:function(res){
console.log(res);
if(res.total>0){
if(res.email){
$('#email_').html(res.email);
}
else{
$('#email_').html('');
}
if(res.fn){
$('#fn_').html(res.fn);
}else{
$('#fn_').html('');
}
if(res.ln){
$('#ln_').html(res.ln);
}else{
$('#ln_').html('');
}
if(res.captcha){
$('#captcha_').html(res.captcha);
grecaptcha.reset();
}else{
$('#captcha_').html('');
}
if(res.subject){
$('#subject_').html(res.subject);
}else{
$('#subject_').html('');
}
if(res.message){
$('#message_').html(res.message);
}else{
$('#message_').html('');
}
if(res.depertment){
$('#dropdown_').html(res.depertment);
}else{
$('#dropdown_').html('');
}
if(res.total>0){
$('#fe_').html('<p class="xxl text-danger">Your submission contain '+res.total+' error(s). Please fix them.</p>');
$('#submit').text('Resend');
//$('#submit').prop('disabled',false);
}else{
}
}
else{
$('#subject_').html('');$('#captcha_').html('');$('#ln_').html('');$('#email_').html('');$('#message_').html('');$('#fn_').html('');$('#fe_').html('');$('#dropdown_').html('');
if(res.status != 'undefined'){
if(res.status==false){
$("#resp").html("<h2 class='text-center text-danger'><b class='glyphicon glyphicon-warning-sign'></b> "+res.message+"</h2>");
}
else if(res.status=true)
{
$("#form").fadeOut(1,function(){
$("#resp").html('');
$('#success').html(res.message);
$('#su').fadeIn(1);
});
if(res.redir){
setTimeout(function(){
window.location=res.redir;
},3000);
}
}else{}
}else{}
}
},
error:function(){
console.log('error');
},
dataType:'json'
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment