I am building a form in my Flask app and want the users to be able to select an option from a <select> menu.
For example:
<select>
<option>Banana</option>
<option>Pineapple</option>
</select>
My current "HTML" for this is
<form action="{{ url_for('contact') }}" method=post>
{{ form.hidden_tag() }}
{{ form.name.label }}
{{ form.name }}
{{ form.company.label }}
{{ form.company }}
{{ form.email.label }}
{{ form.email }}
{{ form.phone.label }}
{{ form.phone }}
{{ form.message.label }}
{{ form.message }}
{{ form.submit }}
</form>
My Python Class for this form is:
class ContactForm(Form):
partner_type = SelectField(
u'Industry Type',
choices = [('Software', 'software'), ('Sales', 'sales')]
)
name = TextField("Name", [validators.Required("Please enter your full name.")])
email = TextField("Email", [validators.Required("Please enter a valid email i.e. you@yourdomain.com"), validators.Email()])
phone = TextField("Phone", [validators.Required("Please enter a valid phone number.")])
company = TextField("Company", [validators.Required("Please enter your company name.")])
message = TextAreaField("Message", [validators.Required("Please include a message regarding this submission.")])
submit = SubmitField("Send")
This all works great for text fields and submit button but I can't seem to figure out how to properly render the <select> options to the form. I tried following the syntax above by doing:
{{ form.industry_type.label }}
{{ form.industry_type }}
but that didn't work. It just added the label and no drop down selector. Is there a proper way to add this to the DOM? The options are static, preset options, so there's nothing dynamic or complex about the list I am trying to render.
Thanks for the help. I am very new to Python so I am still figuring a lot of things out.