title: django forms print select values
body: <p>I am trying to return the selected choice value from a dropdown menu in <code>django</code>. The <code>option</code> (in html) is dynamically populated from the database's model primary key. </p>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;form class="student-ID-search" action="{% url 'new_coach_schedule' %}" method="post" &gt;
  &lt;select class="form-control" id="student_select"&gt;
      &lt;option&gt;Select student ID&lt;/option&gt;
          {% for student_data in students_data %}
              &lt;option value="{{ student_data.pk }}"&gt;{{ student_data.pk }}&lt;/option&gt;
          {% endfor %}
  &lt;/select&gt;
  &lt;/form&gt;
  
  &lt;button class="btn" type="submit" name="search_result" value="select&gt;
      &lt;i class="fa fa-search"&gt;&lt;/i&gt;
  &lt;/button&gt;
  </code></pre>
  
  <p><strong>views.py</strong></p>
  
  <pre><code>students_data = Student.objects.all()
  search_result = NewStudentSearchForm(request.POST)
  if 'search_result' in request.POST:
      test_print_to_screen = search_result['student_select']
      print(test_print_to_screen)
      args = {'students_data': students_data}
      return render(request, 'static/html/new_coach_schedule.html', args)
  else:
      return render(request, 'static/html/new_coach_schedule.html', args)
  </code></pre>
  
  <p><strong>forms.py</strong></p>
  
  <pre><code>class NewStudentSearchForm(forms.Form):
      search_field = forms.CharField(max_length=50)  # This is for something else.
      student_select = forms.ModelChoiceField(queryset=Student.objects.all(), empty_label=None)
  </code></pre>
  
  <p>When I make use of <code>ModelChoiceField</code>, <code>test_print_to_screen</code> does not print out the <code>selected choice</code> that I chose in the html select box.. It prints out everything instead. </p>
  
  <p>EG:</p>
  
  <pre><code>&lt;select name="student_select" id="id_student_select"&gt;
      &lt;option value="5"&gt;Student object (5)&lt;/option&gt;
      &lt;option value="6"&gt;Student object (6)&lt;/option&gt;
      &lt;option value="7"&gt;Student object (7)&lt;/option&gt;
      &lt;option value="8"&gt;Student object (8)&lt;/option&gt;
      &lt;option value="9"&gt;Student object (9)&lt;/option&gt;
      &lt;option value="10"&gt;Student object (10)&lt;/option&gt;
      &lt;option value="11"&gt;Student object (11)&lt;/option&gt;
      &lt;option value="12"&gt;Student object (12)&lt;/option&gt;
      &lt;option value="13"&gt;Student object (13)&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>How can I go about in my <code>forms.py</code> so that when i select the value in my browser, it will return / print out the selected choice back to me?</p>
  
  <hr>
  
  <p><strong>Update</strong></p>
  
  <p>As per the comments, I updated my <code>views.py</code> file to include <code>cleaned_data</code> as follows:</p>
  
  <pre><code>if 'search_result' in request.POST:
      search_result = NewCoachSearchForm(request.POST)
  
      print(search_result)
      if search_result.is_valid():
          test = search_result.cleaned_data['student_select']
          print(test)
      else:
          print(search_result.errors)
  </code></pre>
  
  <p>However, this produces a <code>stacktrace error</code>:</p>
  
  <pre><code>&lt;ul class="errorlist"&gt;&lt;li&gt;student_select&lt;ul class="errorlist"&gt;&lt;li&gt;This field is required.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;
  </code></pre>