Next.js Discord

Discord Forum

Map Function breaking form

Unanswered
Giant panda posted this in #help-forum
Open in Discord
Giant pandaOP
Hi 👋 ,

The form is rendering correctly and as expected, however the data is not appearing in my FormData? When I hardcode the inputs, it works again. Any ideas?

        <form action="" onSubmit={submit}>

          {data.fields.map((field: any) => {
            return (
              <div className="px-3">
                <h3 className="m-3">{field.label}</h3>
                <input type="text" name={field.nameob} className="mx-3 p-1" />
              </div>
            );
          })}
          <input type="submit" value="Submit" className="m-5 p-3 font-semibold" />
        </form>


function submit(event: any) {
  event.preventDefault();
  console.log(event.target);
  const formData = Object.fromEntries(new FormData(event.target).entries());
}

0 Replies