Week 9 Froshims: Why failure despite name and sports chosen
byu/DigitalSplendid incs50
Comment
byu/DigitalSplendid from discussion
incs50
ChatGPT:
The suggestion from Reddit is correct. When submitting a form, the <option>
tags within a <select>
element need a value
attribute to pass data when the form is submitted. Currently, your <option>
tags only contain the display text ({{ sport }}
), but they need a corresponding value that will be submitted with the form. Here’s how you can modify your code to include the value
attribute:
{% extends "layout.html" %}
{% block body %}
<h1>Register</h1>
<form action="/register" method="post">
<input autocomplete="off" autofocus name="name" placeholder="Name" type="text">
<select name="Sport">
<option disabled selected value="">Sport</option>
{% for sport in sports %}
<option value="{{ sport }}">{{ sport }}</option>
{% endfor %}
</select>
<button type="submit">Register</button>
</form>
{% endblock %}