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

158
Visualizações
How to get POST form data that have dynamic IDs?

I have checkboxes inside a form. These checkboxes are a list of persons dynamically created since this list depends on who is logged in. Like, for a supervisor view, it will only list your subordinates.

I'm not sure if I'm missing something but the docs and other answers in SO are all saying that you have to have the id of the input in order to retrieve the form data but in my case, I used the person's ID in the list to come up with the name of the checkbox element. So my checkbox names are like input-{{person_id}}

Now in the post method, I'm not sure how to retrieve the checkboxes in the form. Tried using self.__dict__ but I can't seem to find anything that I can use

link1 - this specifies the name

link2 - this also says that the ID should be pre-determined

link3 - docs also say that if the parameter is not included, an empty list would returned

Maybe there is a workaround where I just get all the elements in the form and make them seen in tornado? Using javascript maybe?

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

0

I'm mistaken, it seems that if you use the same name for a checkbox element for all the dynamic checkboxes you create, then when you submit it to the tornado web handler, it will get the values of all those checkboxes that have that name.

the values are retrieved by using the get_arguments

about 4 years ago · Juan Pablo Isaza Relatório

0

Is this how you mean?

HTML

<form>
  <input type="checkbox" id="box1" name="Name1" checked>
  <label for="box1">Name 1</label>
  <input type="checkbox" id="box2" name="Name2">
  <label for="box2">Name 2</label>
</form>

jQuery

$("form input[type='checkbox']").each(function() {
  console.log($(this).attr('name'))
})

Output

"Name1"
"Name2"
about 4 years ago · Juan Pablo Isaza Relatório

0

You can loop through the request.body_arguments attribute; it's dict which maps arguments names to lists of values (to support multiple values for individual names).

class MyHandler(tornado.web.RequestHandler):

    def post(self):
        for key, value in self.request.body_arguments.items():
            print(f"key {key} has value: {value}")
        ...

There are also arguments (holds both query and body args) and query_arguments (holds only query args) attributes; you can check the docs here.

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