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

164
Visualizações
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 Respostas
Responde à pergunta

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 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