File: /var/www/html/Siyum_old/wp-content/themes/kedushas/js/custom-ajax.js
jQuery(document).ready(function ($) {
$('.send-btn').on('click', function (e) {
e.preventDefault();
// Get email and PDF URL
const email = $('.email-input .form-control').val();
var pdfUrl = $('#email-pdf').val();
var emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
if (!emailRegex.test(email)) {
$('#successAlert')
.text('Please enter a valid email address.')
.css('color', 'red') // Set the text color to red
.show();
setTimeout(function () {
$('#alert').fadeOut(); // Smooth disappearance
}, 2000);
$('#email-input').focus(); // Focus on the email input
return false;
}else{
$('.send-btn').prop('disabled', true);
// Send AJAX request
$.ajax({
url: ajax_params.ajax_url,
method: 'POST',
dataType: 'json',
data: {
action: 'send_pdf_email',
email: email,
pdf_url: pdfUrl,
nonce: ajax_params.nonce,
},
beforeSend: function () {
//$('.send-btn').text('Sending...');
},
success: function (response) {
if (response.success) {
$('#successAlert')
.text('Thank you!.')
.css('color', 'green') // Set the text color to red
.show();
setTimeout(function() {
$('#successAlert').fadeOut(); // Use fadeOut for a smooth disappearance
}, 2000);
document.getElementById('email-input').value='';
$('.send-btn').prop('disabled', false);
} else {
$('#successAlert')
.text(response.data.message)
.css('color', 'red') // Set the text color to red
.show();
setTimeout(function() {
$('#successAlert').fadeOut(); // Use fadeOut for a smooth disappearance
}, 2000);
$('.send-btn').prop('disabled', false);
}
document.getElementById('email-input').value='';
},
error: function () {
alert('An error occurred. Please try again.');
//$('.send-btn').text('Send');
},
});
}
});
});
//-----------------------------Send video series doc email------------------------------------
jQuery(document).ready(function ($) {
$('.emailbtn').on('click', function (e) {
e.preventDefault();
// Get email and PDF URL
var email = $('#input-email').val();
var pdfUrl = $('#email_pdf').val();
var emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
if (!emailRegex.test(email)) {
$('#alert')
.text('Please enter a valid email address.')
.css('color', 'red') // Set the text color to red
.show();
setTimeout(function () {
$('#alert').fadeOut(); // Smooth disappearance
}, 2000);
$('#email').focus(); // Focus on the email input
return false;
}else{
$('.send-btn').prop('disabled', true);
// Send AJAX request
$.ajax({
url: ajax_params.ajax_url,
method: 'POST',
dataType: 'json',
data: {
action: 'send_pdf_email',
email: email,
pdf_url: pdfUrl,
nonce: ajax_params.nonce,
},
beforeSend: function () {
//$('.send-btn').text('Sending...');
},
success: function (response) {
if (response.success) {
//alert(response.data.message);
$('#alert').text('Thank you!').show();
$('#input-email').val('');
setTimeout(function() {
$('#alert').fadeOut(); // Use fadeOut for a smooth disappearance
}, 2000);
$('.send-btn').prop('disabled', false);
$('#input-email').val('');
} else {
//alert(response.data.message);
$('.send-btn').prop('disabled', false);
$('#input-email').val('');
}
},
error: function () {
alert('An error occurred. Please try again.');
},
});
}
});
});
//-------------------------Newsletter------------------------
jQuery(document).ready(function($) {
$('#newsletter-form').on('submit', function(e) {
e.preventDefault(); // Prevent the default form submission
var name = $('#name').val();
var email = $('#email').val();
var emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
if (!emailRegex.test(email)) {
$('#subAlert')
.text('Please enter a valid email address.')
.css('color', 'red') // Set the text color to red
.show();
setTimeout(function () {
$('#subAlert').fadeOut(); // Smooth disappearance
}, 2000);
$('#email').focus(); // Focus on the email input
return false;
}else{
if (name && email) {
$('.btn-submit').prop('disabled', true).text('Subscribing...');
$.ajax({
url: ajax_params.ajax_url, // WordPress built-in variable
method: 'POST',
data: {
action: 'subscribe_newsletter',
name: name,
email: email
},
success: function(response) {
if (response.success) {
$('#subAlert').text('Thank you for subscribing!').show();
setTimeout(function() {
$('#subAlert').fadeOut(); // Use fadeOut for a smooth disappearance
}, 2000);
$('.btn-submit').prop('disabled', false).text('Subscribe');
$('#newsletter-form')[0].reset(); // Reset the form
} else {
$('.btn-submit').prop('disabled', false).text('Subscribe');
}
},
error: function() {
alert('There was an error with the submission. Please try again.');
}
});
} else {
alert('Please fill in both fields.');
}
}
});
});
jQuery(document).ready(function ($) {
$("#contactForm").on("submit", function (e) {
e.preventDefault(); // Prevent default form submission
var formData = {
action: "submit_contact_form",
fname: $("#fname").val(),
lname: $("#lname").val(),
pnum: $("#pnum").val(),
mailid: $("#mailid").val(),
msg: $("#msg").val(),
};
var emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
if (!emailRegex.test($("#mailid").val())) {
$("#form-response").fadeIn();
$('#form-response')
.text('Please enter a valid email address.')
.css('color', 'red') // Set the text color to red
.show();
setTimeout(function() {
$('#form-response').fadeOut();
}, 2000);
setTimeout(function () {
$('#form-response').fadeOut(); // Smooth disappearance
}, 2000);
$('#mailid').focus(); // Focus on the email input
return false;
}else{
$.ajax({
type: "POST",
url: ajax_params.ajax_url, // WordPress AJAX URL
data: formData,
beforeSend: function () {
$(".btn").prop('disabled', true).find("span").text("Sending...");
},
success: function (response) {
$("#form-response").fadeIn();
$("#form-response").html(response);
setTimeout(function() {
$('#form-response').fadeOut();
}, 2000);
$("#contactForm")[0].reset(); // Reset form on success
$(".btn").prop('disabled', false).find("span").text("Send");
},
error: function () {
$("#form-response").fadeIn();
$("#form-response").html("<p style='color:red;'>Error submitting form. Try again.</p>");
$(".btn").prop('disabled', false).find("span").text("Send");
setTimeout(function() {
$('#form-response').fadeOut();
}, 2000);
},
});
}
});
});