1. function exportFormSubmission(formData) {
  2. // Basic input validation
  3. if (!formData || typeof formData !== 'object') {
  4. console.error("Invalid form data provided.");
  5. return null; // Or throw an error
  6. }
  7. //Example validation: check for required fields
  8. if (!formData.name || !formData.email || !formData.message) {
  9. console.warn("Missing required fields. Data not exported.");
  10. return null;
  11. }
  12. //Further validations can be added here based on specific form requirements
  13. if (typeof formData.email !== 'string' || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(formData.email)) {
  14. console.warn("Invalid email format. Data not exported.");
  15. return null;
  16. }
  17. // Prepare the data for export
  18. const exportedData = {
  19. timestamp: new Date().toISOString(),
  20. name: formData.name,
  21. email: formData.email,
  22. message: formData.message,
  23. // Add other relevant fields from formData here
  24. };
  25. // Log the exported data (for debugging/internal tooling)
  26. console.log("Exported Form Submission:", exportedData);
  27. //Return the exported data
  28. return exportedData;
  29. }
  30. //Example Usage:
  31. //const submissionData = {name: "John Doe", email: "john.doe@example.com", message: "Hello"};
  32. //const exportedResult = exportFormSubmission(submissionData);
  33. //if (exportedResult) {
  34. // //Do something with the exported result (e.g., send to an API)
  35. //}

Add your comment