Skip to content

How to use with a dynamic form #20

Closed Answered by DanielHudson2
DanielHudson2 asked this question in Q&A
Discussion options

You must be logged in to vote

I've managed to find what I think is a viable solution to this.

As i'm controlling state in my form I have an array of objects called "People" so in my handlesubmit function I can access this and pass it into EmailJS as a field that I can access as a dynamic variable.

const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();

	// Format the form data for submission
	const formattedData = people.map((person) => {
		return `First Name: ${person.firstName}
		Last Name: ${person.lastName}
		Attending: ${person.attending ? 'Yes' : 'No'}
		Duration: ${person.duration}
		Starter: ${person.starter}
		Main Course: ${person.mainCourse}
		Dessert: ${person.dessert}
	`;
	});

	const emailCont…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by DanielHudson2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant