2

I have a flaskform with the following categories:

`class TestForm(FlaskForm):
    question: ('Question')
    likelihood = SelectField('Likelihood',choices=[('1','1'),('2','2'),('3','3'),('4','4'),('5','5')])
    impact = SelectField('Impact', choices=[('1','1'),('2','2'),('3','3'),('4','4'),('5','5')])
   `

I have an html page with multiple questions, which each need a response of likelihood and impact. Each question is in a table, together with the flaskforms. So for instance:

Table 1:

  1. Question column: I want to buy icecream.
  2. Likelihood column: the likelihood flaskform
  3. Impact column: the impact flaskform

Table 2:

  1. Question column: I want to buy sunlotion.
  2. Likelihood column: the likelihood flaskform
  3. Impact column: the impact flaskform

However, when I submit my form, it only takes the first result to my database. This is the route of page that should submit the form:

`@projects.route("/project/<int:project_id>/concept", methods=['GET', 'POST'])
@login_required
def concept(project_id):
    form = TestForm()
    project = Project.query.get_or_404(project_id)
    if form.validate_on_submit():
            test = Testresponse(form.likelihood.data, impact=form.impact.data)         
            db.session.add(test)
            db.session.commit()
            flash('Your data has been processed', 'success')
            return redirect(url_for('projects.concept', project_id=project_id))
    return render_template('create_concept.html', title='concept',
                           form=form, legend='project', project=project,project_id=project_id)`

The database table is called Testresponse. I somehow need to code in a part that specifies that the submit button should sent the data of all the questions to the database, and not just the first one. Maybe something like: for every table, take form.likelihood.data and form.impact.data.

I am a bit stuck because I would not know how to make a loop like that for html tables. Can somebody please help me, or provide an alternative idea?

0 Answers0