Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

165
Vistas
Why would a <button>, with attribute type="submit", not be submitted with the form when using HTMLFormElement.submit()?

I happen to have the following form:

<form method="post" action=<?php echo htmlspecialchars($_SERVER['REQUEST_URI']); ?> enctype="multipart/form-data">
  <button type="submit" name="identifier" value="wikipedea_form">
    Add Post
  </button>
</form>

I use jquery to submit this form as

$("form").submit();

This doesn't send the post data $_POST["identifier"]. I assume jQuery uses HTMLFormElement.submit() under the hood. The MDN docs say that:

<input> with attribute type="submit" will not be submitted with the form when using HTMLFormElement.submit()...

I think the same applies to the button tag as well. Just to be 100% sure I am asking here. May be it depends on the browser etc etc...

So, Would <button> with attribute type="submit" not be submitted with the form when using HTMLFormElement.submit()? Please quote official documentation to back up your answer.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Only successful controls are submitted in normal form submission.

Submit buttons are only successful if they are used to submit the form (or if the form is submitted via Enter in a single text input in which case the default submit button is successful). This lets you distinguish which button was used to submit the form in cases such as:

<button name="action" value="like">Like</button>
<button name="action" value="dislike">Dislike</button>

Trigging form submission with JS bypasses the selection of a submit button.


  1. For each element field in controls, in tree order:

    1. If any of the following is true:
      • The field element has a datalist element ancestor.
      • The field element is disabled.
      • The field element is a button but it is not submitter.
      • The field element is an input element whose type attribute is in the Checkbox state and whose checkedness is false.
      • The field element is an input element whose type attribute is in the Radio Button state and whose checkedness is false.

    Then continue.

— https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#constructing-the-form-data-set


If you want to submit data with a form every time it is submitted, regardless of how it was submitted: Use <input type="hidden" ...>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda