HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: /var/www/html/wpcurated/wp-content/themes/curated/js/custom.js
jQuery(document).ready(function ($) {
  // Initialize Parsley on the form
  $('#ajax-form').parsley();

  $('#ajax-form').on('submit', function (e) {
    e.preventDefault();

    // Check if the form is valid
    if ($('#ajax-form').parsley().isValid()) {
      // Collect form data
      let formData = {
        action: 'submit_ajax_form', // AJAX action name
        name: $('#name').val(),
        email: $('#email').val(),
        message: $('#message').val(),
      };

      $('.contact-us').prop('disabled', true).text('Sending.....');

      // AJAX Request
      $.ajax({
        url: ajaxurl, // AJAX URL provided by WordPress
        type: 'POST',
        data: formData,
        success: function (response) {
          $('#successAlert').text('Thank you for contacting us!').show();
          $('#ajax-form').trigger('reset'); // Clear the form
          setTimeout(function () {
            $('#successAlert').fadeOut(); // Smooth disappearance
          }, 10000);
          $('.contact-us').prop('disabled', false).text('Send Message');
        },
        error: function (xhr, status, error) {
          $('#dangerAlert').text('Something went wrong. Please try again.').show();
          setTimeout(function () {
            $('#dangerAlert').fadeOut();
          }, 5000);
          $('.contact-us').prop('disabled', false).text('Send Message');
        },
      });
    } else {
      // If the form is not valid, Parsley will handle the validation errors
      // $('#dangerAlert').text('Please fill out the form correctly.').show();
      // setTimeout(function () {
      //   $('#dangerAlert').fadeOut();
      // }, 1000);
    }
  });
});



//   jQuery(document).ready(function ($) {
//     $('.primary-btn').on('click', function (e) {
//         e.preventDefault();

//         // Collect form data
//         var formData = {
//             action: 'submit_intake_form',
//             security: ajaxurl,
//             full_name: $('input[placeholder="Enter full Name"]').val(),
//             contact_number: $('input[placeholder="Enter Contact number"]').val(),
//             mail_id: $('input[placeholder="Enter mail id"]').val(),
//             reason: $('input[placeholder="Enter Reason"]').val(),
//             description: $('#description').val(),
//         };

//         // AJAX request
//         $.ajax({
//             url: ajaxurl,
//             type: 'POST',
//             data: formData,
//             success: function (response) {
//                 if (response.success) {
//                   $('#successAlert').text('Thank you for contacting us!').show();
//                   $('#contact_form').trigger('reset'); // Clear the form
//                   setTimeout(function() {
//                       $('#successAlert').fadeOut(); // Use fadeOut for a smooth disappearance
//                   }, 10000);
//                   $('.btn').prop('disabled', false).text('Send Message');
//                 } else {
//                   $('#dangerAlert').text(response.data || 'There was an error. Please try again.').show();
//                   $('.btn').prop('disabled', false).text('Send Message');
//                 }
//             },
//             error: function (xhr, status, error) {
//                 console.error('AJAX Error: ', error);
//             },
//         });
//     });
// });


jQuery(document).ready(function ($) {
  // Handle the cancel button click
  $(".btn-cancel").on("click", function (e) {
      e.preventDefault(); // Prevent any default action if it's a button or link

      // Clear all input fields
      $(".intake-form-sec input").val("");

      // Clear all textarea fields
      $(".intake-form-sec textarea").val("");

      // Clear error messages or info labels
      $(".intake-form-sec .info-label").text("").removeClass("error");
  });
});

//--------------------------------------------------------------------------------------------
jQuery(document).ready(function ($) {
    // Initialize Parsley
    $('#customForm').parsley();
  
    $('#customForm').on('submit', function (e) {
        e.preventDefault();
  
        // Check if form is valid
        if ($(this).parsley().isValid()) {
            let formData = new FormData(this); // Use FormData to include files
            formData.append('action', 'send_form_email'); // WordPress AJAX action
  
            let $submitBtn = $('.apply-btn'); 
            let originalHtml = $submitBtn.html(); 
  
            $submitBtn.prop('disabled', true).html('<span>Submitting...</span>');
  
            $.ajax({
                url: ajaxurl, // WordPress AJAX URL
                type: 'POST',
                data: formData,
                contentType: false, // Important for file upload
                processData: false, // Important for file upload
                success: function (response) {
                    $('#successAlert').text('Thank you for contacting us!').show();
                    $('#customForm').trigger('reset'); // Clear the form
                    $('#file-display').text('Drag and Drop file here Choose File');
                    $('#cover-letter-display').text('Drag and Drop file here Choose File');
                    setTimeout(function () {
                        $('#successAlert').fadeOut();
                    }, 10000);
                },
                error: function () {
                    $('#dangerAlert').text('There was an error. Please try again.').show();
                    setTimeout(function () {
                        $('#dangerAlert').fadeOut();
                    }, 10000);
                },
                complete: function () {
                    $submitBtn.prop('disabled', false).html(originalHtml);
                },
            });
        } else {
            console.log('Form validation failed.');
        }
    });
  });

  
// jQuery(document).ready(function ($) {
//   // Initialize Parsley
//   $('#customForm').parsley();

//   $('#customForm').on('submit', function (e) {
//       e.preventDefault();

//       // Check if form is valid
//       if ($(this).parsley().isValid()) {
//           let formData = $(this).serialize();
//           let $submitBtn = $('.apply-btn'); // Target the button
//           let originalHtml = $submitBtn.html(); // Store the original HTML structure

//           $submitBtn.prop('disabled', true).html('<span>Submitting...</span>'); // Change button content

//           $.ajax({
//               url: ajaxurl, // WordPress AJAX URL
//               type: 'POST',
//               data: {
//                   action: 'send_form_email',
//                   form_data: formData,
//               },
//               success: function (response) {
//                   $('#successAlert').text('Thank you for contacting us!').show();
//                   $('#customForm').trigger('reset'); // Clear the form
//                   $('#file-display').text('Drag and Drop file here Choose File');
//                   $('#cover-letter-display').text('Drag and Drop file here Choose File');
//                   setTimeout(function () {
//                       $('#successAlert').fadeOut();
//                   }, 10000);
//               },
//               error: function () {
//                   $('#dangerAlert').text('There was an error. Please try again.').show();
//               },
//               complete: function () {
//                   // Reset button to its original state
//                   $submitBtn.prop('disabled', false).html(originalHtml);
//               },
//           });
//       } else {
//           console.log('Form validation failed.');
//       }
//   });
// });



//---------------------------------Refer a patient------------------------------
jQuery(document).ready(function ($) {
  $('.intake-form-wrapper').on('submit', function (e) {
      e.preventDefault(); // Prevent default form submission

      // Perform form validation using Parsley before submitting
      if ($(this).parsley().isValid()) {
          const formData = $(this).serialize(); // Serialize form data

          $('.btn-submit').prop('disabled', true).text('Submitting..'); // Disable the submit button and change text

          $.ajax({
              url: ajaxurl, // WordPress AJAX URL
              type: 'POST',
              data: {
                  action: 'submit_intake_form', // Custom action name
                  form_data: formData
              },
              beforeSend: function () {
                  // Optional: Show a loading spinner or message
                  console.log('Submitting...');
              },
              success: function (response) {
                  if (response.success) {
                      $('#successAlert').text('Thank you for contacting us!').show();
                      $('.intake-form-wrapper')[0].reset(); // Reset the form
                      setTimeout(function() {
                          $('#successAlert').fadeOut(); // Use fadeOut for a smooth disappearance
                      }, 10000);
                      $('.btn-submit').prop('disabled', false).text('Next');
                  } else {
                      alert('There was an error: ' + response.data.message);
                      $('.btn-submit').prop('disabled', false).text('Next');
                  }
              },
              error: function (xhr, status, error) {
                  console.error('AJAX Error:', status, error);
                  alert('An error occurred while submitting the form.');
                  $('.btn-submit').prop('disabled', false).text('Next'); // Re-enable submit button after error
              }
          });
      } else {
          // If the form is not valid, show a general error alert
          alert('Please fill in all required fields.');
      }
  });
});


jQuery(document).ready(function ($) {
  function performSearch(searchQuery) {
      $.ajax({
          url: ajaxurl,
          method: 'GET',
          data: {
              action: 'ajax_blog_search', // Your AJAX action
              s: searchQuery || '', // Pass the search query or empty string for all posts
          },
          success: function (response) {
              // Update the blog section with the search results
              $('.blog-listing-blks').html(response);
          },
          error: function () {
              alert('An error occurred while searching.');
          }
      });
  }

  // Trigger search on button click
  $('#searchBlog').on('click', function () {
      var searchQuery = $('input[name="s"]').val();
      performSearch(searchQuery);
  });

  // Trigger search on 'Enter' key press
  $('input[name="s"]').on('keypress', function (e) {
      if (e.which === 13) { // Enter key code
          e.preventDefault(); // Prevent the form submission or default action
          var searchQuery = $(this).val();
          performSearch(searchQuery);
      }
  });

  // Detect when the input field is cleared and show all posts
  $('input[name="s"]').on('input', function () {
      var searchQuery = $(this).val();
      if (searchQuery.trim() === '') {
          // If the input field is empty, fetch all posts
          performSearch('');
      }
  });
});