Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

177
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!