Get in touch with us

Want Nutriliq to support you with your feed supplement or have a question? Let us now in the form below!

				
					console.log( 'Code is Poetry' );

<script>
    window.dataLayer = window.dataLayer || [];
    window.dataLayer.push({
        'event': 'form_submit',
        'user_properties': {!! json_encode($userProperties) !!}
    });
    
    // On form submit
    form.addEventListener("submit", (event) => {
      event.preventDefault(); // Prevent default form submission
    
      const formData = getFormData("New Form");
    
      if (formData) {
        // Do something with the form data (e.g., send it via AJAX)
        console.log(formData); // Example: Log data to console
      }
    });
    
    function getFormData(formName) {
      // Get the form element
      const form = document.getElementById(formName);
    
      // Check if form exists
      if (!form) {
        console.error("Form not found:", formName);
        return [];
      }
    
      // Create an empty object to store data
      const formData = {};
    
      // Loop through all form elements
      for (const element of form.elements) {
        // Check for valid input types
        if (["text", "email", "password", "hidden", "checkbox", "radio"].includes(element.type)) {
          const name = element.name;
          const value = element.value;
    
          // Handle checkbox and radio buttons (they might return an array)
          if (element.type === "checkbox" || element.type === "radio") {
            if (element.checked) {
              formData[name] = value; // Add value if checked
            } else if (!formData.hasOwnProperty(name)) { // Handle unchecked checkboxes
              formData[name] = ""; // Add empty string for unchecked boxes
            }
          } else {
            formData[name] = value;
          }
        }
      }
    
      // Return the collected data
      return formData;
    }
    
</script>