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

253
Visualizações
How can I get data from another form in Flask using the button?

I want to implement on the web page the sequential display of blocks with data input (i.e. after filling in the first block and pressing the "OK" button, the second block opens, then the third). The button in the last block sends a request to write data.

The problem is that with the help of reguest.form.get I can only receive data from the form in which the button is located. How can I get data from other forms?

I am new to Flask and my code may not be very correct. Maybe you should use javascript?

flask.py

@app.route('/scenario',methods = ['GET', 'POST'])
def control_task():
   if(request.form.get('add') == 'add'):
ts.add_task(request.form['host_info'].get('task'),request.form['host_info'].get('hostId'), request.form['role_info'].get('role'))

html:

<button id='addTask_btn' onclick="hidden_element(addTask_block)">add task</button>

<span id="addTask_block" hidden="true">
    <form name="host_info">
        <select name="task">
           {% for test in tests %}
           <option>{{test}}</option>
           {% endfor %}
        </select>

    </form name='service_info>
        <button onclick="hidden_element('step_2')">Ok</button>

        <div hidden="true" id="step_2">
            <form name="service_info">
                <select id="service" name="service">
                {% for role in hosts[0].roles %}
                <option value="{{role.serviceName}}">{{role.serviceName}}</option>
                {% endfor %}
                </select>
            </form>

            <button onclick="hidden_element('step_3')">Ok</button>
            <button onclick="hidden_element('step_3')">Back</button>

        </div>

        <div id="step_3" hidden="true">
            <form method="post" action="/scenario" name="role_info">
                <select name="role">
                {% for role in hosts[0].roles %}
                <option name="{{role.roleType}}">{{role.roleType}}</option>
                {% endfor %}
                </select>
                <button onclick="hidden_element(step_3)" name="add" value="add">Ok</button>
            </form>
        </div>
</span>


<script type="text/javascript">
    function hidden_element(id){
    document.getElementById(id).hidden = !document.getElementById(id).hidden;
    }
</script>

about 4 years ago · Juan Pablo Isaza
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