File: /var/www/html/WPYadBatya/wp-content/themes/yad-batya/js/custom.js
jQuery(document).ready(function($) {
$('#volunteer-form').parsley();
$('#volunteer-form').on('submit', function(e) {
e.preventDefault();
if ($(this).parsley().isValid()) {
var formData = $(this).serialize();
$.ajax({
type: "POST",
url: window.ajaxurl, // Use wp_localize_script variable
data: {
action: 'send_form_email',
form_data: formData,
},
beforeSend: function() {
$('.contact-btn').prop('disabled', true).text('Submitting...').css({
'color': 'white',
'font-size': '15px'
});
},
success: function(response) {
if (response.success) {
$('#form-message')
.html('<span style="color:green;">' + response.data + '</span>')
.fadeIn();
.delay(2000) // Wait for 2 seconds
.fadeOut(500); // Fade out in 0.5 seconds
$('.contact-btn').prop('disabled', false).text('Submit').css({
'color': 'white',
'font-size': '15px'
});
$('#volunteer-form')[0].reset();
} else {
$('#form-message').html('<span style="color:red;">' + response.data + '</span>');
$('.contact-btn').prop('disabled', false).text('Submit').css({
'color': 'white',
'font-size': '15px'
});
$('#volunteer-form')[0].reset();
}
}
});
}
});
});
jQuery(document).ready(function($) {
$('#subscribe-btn').on('click', function(e) {
e.preventDefault();
$('#form-message').html('');
var theme_directory = "https://yadbatya.spericorn.com/wp-content/themes/yad-batya";
var email = $('#email').val();
if (email == "") {
$('#form-message')
.html('<span style="color:red;">Please enter an email address.</span>')
.fadeIn(); // Ensure it's visible
return;
}
$.ajax({
type: 'POST',
url: ajaxurl, // WordPress AJAX URL
data: {
action: 'subscribe_newsletter',
email: email,
},
beforeSend: function() {
// $('.btn-subscribe').html('<span style="color:#975FA9;">Submitting...</span>');
$('.btn-subscribe').prop('disabled', true).html('<span>Submitting...</span><img src="' + theme_directory + '/img/right-arrow.svg" class="img" />').css({
'color': '#975FA9',
'font-size': '15px'
});
},
success: function(response) {
if (response.success) {
$('#form-message')
.html('<span style="color:green;">' + response.data + '</span>')
.fadeIn(); // Ensure it's visible
$('.btn-subscribe').prop('disabled', false).html('<span>Subscribe</span><img src="' + theme_directory + '/img/right-arrow.svg" class="img" />').css({
'color': '#975FA9',
'font-size': '15px'
});
$('#subscribe-form')[0].reset();
} else {
$('#form-message').html('<span style="color:red;">' + response.data + '</span>')
.fadeIn(); // Ensure it's visible
$('.btn-subscribe').prop('disabled', false).html('<span>Subscribe</span><img src="' + theme_directory + '/img/right-arrow.svg" class="img" />').css({
'color': '#975FA9',
'font-size': '15px'
});
}
},
error: function() {
$('#form-message').html('<span style="color:red;">There was an error submitting the form.</span>')
.fadeIn(); // Ensure it's visible
$('.btn-subscribe').prop('disabled', false).html('<span>Subscribe</span><img src="<?php echo get_template_directory_uri(); ?>/img/right-arrow.svg" class="img" />').css({
'color': '#975FA9',
'font-size': '15px'
});
}
});
});
});
jQuery(document).ready(function($) {
$('#donationForm').parsley(); // Initialize Parsley validation
var themeUrl = "https://yadbatya.spericorn.com/wp-content/themes/yad-batya";
$('#sponserbtn').click(function(e) {
e.preventDefault(); // Prevent default form submission
$('#form-message').html('');
var form = $('#donationForm');
// Validate the form using Parsley
if (!form.parsley().isValid()) {
form.parsley().validate(); // Show validation errors
return; // Stop execution if form is invalid
}
var cpatchaerrorMsg = document.getElementById("captcha-message");
// Check if ReCAPTCHA is completed
var recaptchaResponse = grecaptcha.getResponse();
if (recaptchaResponse.length === 0) {
cpatchaerrorMsg.style.display = "block";
//alert('Please verify that you are not a robot.');
return;
}
const month = document.getElementById('months').value;
const year = document.getElementById('exp_date').value;
const errorMessage = document.createElement('span');
var monthyearmsg = document.getElementById("monthyear");
const currentDate = new Date();
const currentYear = currentDate.getFullYear();
const currentMonth = currentDate.getMonth() + 1; // JavaScript months are 0-based, so we add 1
if (parseInt(year) < currentYear || (parseInt(year) === currentYear && parseInt(month) < currentMonth)) {
e.preventDefault(); // Prevent form submission
monthyearmsg.style.display = "block";
monthyearmsg.scrollIntoView({ behavior: "smooth", block: "center" });
return;
} else {
//alert('sgertgrw');
monthyearmsg.style.display = "none"; // Hide error message
}
const radioButtons = document.querySelectorAll('input[name="flexRadioDefault"]');
const donationInput = document.getElementById("donationAmount");
var errorMsg = document.getElementById("amountError");
let isChecked = false;
radioButtons.forEach(radio => {
if (radio.checked) {
isChecked = true;
}
});
if (!isChecked && donationInput.value.trim() === "") {
//alert('test111');
errorMsg.style.display = "block"; // Show error message
errorMsg.scrollIntoView({ behavior: "smooth", block: "center" });
return;
} else {
//alert('sgertgrw');
errorMsg.style.display = "none"; // Hide error message
}
// Prepare form data
var formData = {
donor_fname: $('#fname').val(),
donor_lname: $('#lname').val(),
donor_address: $('#location').val(),
donor_city: $('#city').val(),
donor_state: $('#state').val(),
zip: $('#zip').val(),
card_number: $('#card_number').val(),
month: $('#months').val(),
year: $('#exp_date').val(),
donation_frequency: $('input[name="options"]:checked').val(),
donor_email: $('#email').val(), // Fixed email field reference
donation_total: $('input[name="flexRadioDefault"]:checked').val() || $('#donationAmount').val(),
gift_type: $('input[name="gift_type"]:checked').val(),
captcha_response: recaptchaResponse // Send the reCAPTCHA response
};
// AJAX Request
$.ajax({
url: ajaxurl, // WordPress AJAX handler
type: 'POST',
data: {
action: 'process_donation', // Action hook for backend processing
form_data: formData
},
beforeSend: function() {
$('#sponserbtn').prop('disabled', true).text('Submitting...').css({
'color': 'white',
'font-size': '15px'
});
},
success: function(response) {
if (response.success === true && response.data.transactionStatus === 'success') {
$('#form-message').html('<span style="color:green;">Thank you for your donation!</span>')
.fadeIn();
$('#donationForm')[0].reset(); // Reset form after successful submission
grecaptcha.reset(); // Reset ReCAPTCHA
}
else if (response.data.transactionStatus === 'error' || response.data.subscriptionStatus === 'error') {
$('#form-message').html('<span style="color:red;">' + response.data.message + '</span>')
.fadeIn();
// $('#donationForm')[0].reset(); // Reset form after successful submission
grecaptcha.reset(); // Reset ReCAPTCHA
}
else if (response.success === true && response.data.subscriptionId) { // Fixed comparison
$('#form-message').html('<span style="color:green;">Thank you for your donation! Your subscription has been created.</span>')
.fadeIn();
$('#donationForm')[0].reset(); // Reset form after successful submission
grecaptcha.reset(); // Reset ReCAPTCHA
}
else if (response.success === false && response.data.subscriptionId=='') { // Fixed comparison
$('#form-message').html('<span style="color:green;">' + response.data.message + '</span>')
.fadeIn();
$('#donationForm')[0].reset(); // Reset form after successful submission
grecaptcha.reset(); // Reset ReCAPTCHA
}
else
{
}
console.log(response);
$('#sponserbtn').prop('disabled', false).html('Submit <img class="img" src="' + themeUrl + '/img/right-arrow.svg" class="img" />').css({
'color': 'white',
'font-size': '15px'
});
},
error: function(xhr, status, error) {
alert('An error occurred while submitting the form.');
$('#sponserbtn').prop('disabled', false).html('Submit <img class="img" src="' + themeUrl + '/img/right-arrow.svg" class="img" />').css({
'color': 'white',
'font-size': '15px'
});
}
});
});
});
// jQuery(document).ready(function($) {
// $('#donationForm').on('submit', function(event) {
// event.preventDefault();
// var amount = $('#donationAmount').val();
// $.ajax({
// url: '<?php echo admin_url("admin-ajax.php"); ?>',
// type: 'POST',
// data: {
// action: 'process_donation_payment',
// donation_amount: amount
// },
// success: function(response) {
// if (response.success) {
// window.location.href = response.data.redirect;
// } else {
// alert(response.data.message);
// }
// }
// });
// });
// });
// document.addEventListener("DOMContentLoaded", function () {
// const donateButton = document.getElementById("sponserbtn"); // Assuming you have a submit button
// const radioButtons = document.querySelectorAll('input[name="flexRadioDefault"]');
// const donationInput = document.getElementById("donationAmount");
// var errorMsg = document.getElementById("amountError");
// donateButton.addEventListener("click", function (event) {
// let isChecked = false;
// radioButtons.forEach(radio => {
// if (radio.checked) {
// isChecked = true;
// }
// });
// if (!isChecked && donationInput.value.trim() === "") {
// errorMsg.style.display = "block";
// event.preventDefault(); // Prevent form submission
// }
// else {
// errorMsg.style.display = "none"; // Hide error message if valid
// }
// });
// });
document.addEventListener("DOMContentLoaded", function () {
const donationInput = document.getElementById("donationAmount");
const radioButtons = document.querySelectorAll('input[name="flexRadioDefault"]');
// If user types in the input, uncheck all radio buttons
donationInput.addEventListener("input", function () {
radioButtons.forEach(radio => radio.checked = false);
});
// If user selects a radio button, clear the input field
radioButtons.forEach(radio => {
radio.addEventListener("change", function () {
if (this.checked) {
donationInput.value = "";
}
});
});
});
// jQuery(document).ready(function($) {
// const donationInput = $("#donationAmount");
// const radioButtons = $("input[name='flexRadioDefault']");
// // Disable radio buttons when typing in the input field
// donationInput.on("input", function() {
// if ($(this).val().trim() !== "") {
// radioButtons.prop("disabled", true).prop("checked", false); // Disable and uncheck radio buttons
// } else {
// radioButtons.prop("disabled", false); // Enable radio buttons when input is empty
// }
// });
// // Disable input field when selecting a radio button
// radioButtons.on("change", function() {
// donationInput.val("").prop("disabled", true); // Clear input and disable it
// $('#amountError').hide();
// });
// // Re-enable input when all radio buttons are unchecked
// radioButtons.on("click", function() {
// if (!$("input[name='flexRadioDefault']:checked").length) {
// donationInput.prop("disabled", false);
// $('#amountError').hide();
// }
// });
// });
document.getElementById('ncard').addEventListener('input', function(event) {
const input = event.target.value;
const regex = /^[A-Za-z\s'-]*$/;
if (!regex.test(input)) {
event.target.value = input.replace(/[^A-Za-z\s'-]/g, '');
} else {
}
});
document.getElementById('fname').addEventListener('input', function(event) {
const input = event.target.value;
const regex = /^[A-Za-z\s'-]*$/;
if (!regex.test(input)) {
event.target.value = input.replace(/[^A-Za-z\s'-]/g, '');
} else {
}
});
document.getElementById('lname').addEventListener('input', function(event) {
const input = event.target.value;
const regex = /^[A-Za-z\s'-]*$/;
if (!regex.test(input)) {
event.target.value = input.replace(/[^A-Za-z\s'-]/g, '');
} else {
}
});