const contactForm = document.getElementById('contactForm');
const infoParag = document.getElementById('infoParag');
const contPHP = "contact.php";

contactForm.addEventListener('submit', function(event) {
    event.preventDefault();
    
    const contactFormObj = new FormData(contactForm);
    sendEmail(contactFormObj);
});

async function sendEmail(contform) {
    const response = await fetch(contPHP, 
    {
        method: 'POST',
        body: contform
    });
    //uploadParag.textContent = "test 3";
    const phpResponse = await response.text();
    //infoParag.textContent = phpResponse;
    
    //call function to reset inputs if message is sent
    if (phpResponse.includes("OK")) {
        infoParag.textContent = "Your message has been sent!";
        contactForm.reset();
    } else {
        infoParag.textContent = "Message not sent, try to contact us directly at contact@myguardcam.com";
    } 
}
