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

174
Visualizações
How to take a variable from inside a html form that wasn't inputted by the user and output it to flask app?

<form action="{{ url_for('searchResult') }}" method="POST">
                          <ul style="margin-bottom: 10px;" class="list-group list-group-flush">
                            <li class="list-group-item"><input type="hidden" value="location"/> {{row[0]}}</li>
                            <li class="list-group-item">Capacity :{{row[1]}}</li>
                            <li class="list-group-item">Prices per night(in GBP):</li>
                            <li class="list-group-item">Off-Peak - {{row[2]}}</li>
                            <li class="list-group-item">Peak (Apr-Sept) - {{row[3]}}</li>
                            <li class="list-group-item"><input type="submit" value="More Info"class="btn btn-outline-info"/><input type="submit" class="btn btn-outline-success" value="Book"/></li>
                          </ul>
                        </form>

    @app.route('/Locations', methods=['GET', 'POST'])
def searchResult():
    if request.method == 'POST':
        locationInput = request.form['location']
        searchedLocation = locationInput.capitalize()
        try:       
            conn = connection.connection()
            if conn != None:    #Checking if connection is None    
                print('MySQL Connection is established')                          
                cursor = conn.cursor()    #Creating cursor object
                cursor.execute('USE {};'.format(DB_NAME)) #use database                
                sqlStatement = "SELECT * FROM locations;"
                cursor.execute(sqlStatement)
                rows = cursor.fetchall()
                cursor.close() 
                match = False
                for row in rows:
                    if row[0] == searchedLocation:
                        match = True
                        return render_template('locations/' + searchedLocation + '.html')
                if match == False:
                    return render_template('searchError.html', searchedLocation = searchedLocation)                                    
        except:
            conn.rollback()

When I hit one of the submit buttons I want to take the value of row[0] out into a flask app. The row values have come from an 3d array from the flask app, this block of html is looped over the columns. I want to receive the value of the location for that specific block that I clicked the submit button on so that I can move to a new page specifically about that location, and I don't want to user to see an input box. I'm confused and any help would be much appreciated, thanks.

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

0

There are several things wrong with this. First, a "hidden" item is not going to be visible, so it should not have a list item (unless you want the user to see it). Second, if you want the hidden item to be called "location", then it's NAME needs to be location. The value is what you want sent back. So:

 <input type="hidden" name"location" value="{{row[0]}}">
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