Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

217
Visualizações
Should I use a <form> or just a <div> to create a form?

I am using React JS with Apollo client, when I want to create like a registration form for example, I usually create a div which contains some input fields and a button, the button is not of type "submit" it is just a regular button with an "onClick()" event that runs the registration function ... it does the job and I like the way the registration logic runs without passing any data through the URL as well as it doesn't need to refresh the page after each registration approach.

So the question is which way is better ?

  1. Using a form tag to do form things
  2. Using a div instead

NOTE: I know that there is some packages that can handle these situations like "Formik" for example ... but I like to code everything my self.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

In my opinion, it's always better to keep using semantic HTML tag e.g <form> for form.

There are some advantages using <form> from what I've known so far:

  1. Support CSS pseudoclass :invalid and :valid which may be handy
  2. Better accessibility

Note: Using the element will automatically communicate a section of content as a form landmark, if it is provided an accessible name. Developers should always prefer using the correct semantic HTML element over using ARIA.

Source: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/form_role#description

For CSS pseudoclass demo, you could check my Stackblitz

about 4 years ago · Juan Pablo Isaza Relatório

0

I would recommend using <form> and make your <button> of type="submit".

Instead of adding an EventHandler to the button on onClick, I would bind it to the onSubmit event of the form.

With event.preventDefault() you stop the submission of the form and you can handle your registration logic there.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda