title: How to submit a form with an href in Django?
body: <p>I have a link that when clicked, should submit a form that contains an invisible field via a post request. I then should be able to get the field value like:</p>
  
  <pre><code>var = request.POST.get('name_of_var', '')
  </code></pre>
  
  <p>After looking at a few posts, I can't seem to get this to work. This is what I have so far:</p>
  
  <pre><code>&lt;form id="form-id" method="post"&gt;
      &lt;li&gt; 
          &lt;input type="hidden" value="{{ obj }}" name="name_of_var"&gt;
          &lt;a href="/activities" onclick="document.getElementById('form-id').submit();"&gt; {{obj}} &lt;/a&gt;
      &lt;/li&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>In my view I have something like this, but a POST request is never triggered. What could be the issue here?:</p>
  
  <pre><code>if request.POST:
          var = request.POST.get('name_of_var', '')
          return render_to_response('activities/display_activities.html', var)
  </code></pre>
  
  <p><strong>EDIT</strong>: Here is my views.py:</p>
  
  <pre><code>def index(request):
      if request.method == "POST":
          var = request.POST.get('name_of_var', '')
          return render_to_response('activities/display_activities.html', var)
  
      category1 = Service.objects.filter(category = 'Sports')
      category2 = Service.objects.filter(category = 'Dance')
      category3 = Service.objects.filter(category = 'Music')
      category4 = Service.objects.filter(category = 'Academics')
      category5 = Service.objects.filter(category = 'Art')
      category6 = Service.objects.filter(category = 'College')
  
      subcat1 = []
      subcat2 = []
      subcat3 = []
      subcat4 = []
      subcat5 = []
      subcat6 = []
  
      for obj in category1:
          subcat1.append(obj.subcategory)
      subcat1 = list(set(subcat1)) 
  
      for obj in category2:
          subcat2.append(obj.subcategory)
      subcat2 = list(set(subcat2)) 
  
      for obj in category3:
          subcat3.append(obj.subcategory)
      subcat3 = list(set(subcat3)) 
  
      for obj in category4:
          subcat4.append(obj.subcategory)
      subcat4 = list(set(subcat4)) 
  
      for obj in category5:
          subcat5.append(obj.subcategory)
      subcat5 = list(set(subcat5)) 
  
      for obj in category6:
          subcat6.append(obj.subcategory)
      subcat6 = list(set(subcat6)) 
  
      return render_to_response('activities/activities.html', {'user': request.user,  
          'category1':category1, 'category2':category2, 'category3':category3, 
          'category4':category4, 'category5':category5, 'category6':category6,  
          'subcat1':subcat1,'subcat2':subcat2, 'subcat3':subcat3, 
          'subcat4':subcat4, 'subcat5':subcat5,'subcat6':subcat6  })
  </code></pre>