Next.js Discord

Discord Forum

is there a way to make a button out of a form tag that can submit?

Answered
Havana posted this in #help-forum
Open in Discord
HavanaOP
is there a way to make a button out of a form tag that can submit?

sample code:
import { useForm } from "react-hook-form";
import { Button, Input } from "@chakra-ui/react";

export default function Checkou() {
  const { register, handleSubmit } = useForm();

  const onSubmit = (data) => console.log(data);

  return (
    <div>
      <form onSubmit={handleSubmit(onSubmit)}>
        <Input {...register("firstName")} placeholder="First name" />
        <Input {...register("lastName")} placeholder="Last name" />
        <Input {...register("address")} placeholder="Address" />
        <Input {...register("city")} placeholder="City" />
        <Input {...register("zip")} placeholder="ZIP Code" />
      </form>
      <Button type="submit">Submit</Button>
    </div>
  );
};

1 Reply