title: Django How to submit and handle form data in class based views
body: <p>Can anybody tell me how to handle form submit and fields using class based views.
  Here is my views.py  </p>
  
  <pre><code>class ProfileView(FormView):
      template_name='profile.html'
      form_class = UnregisterMealForm
      context={}
      @method_decorator(login_required)
      def form_valid(self, form):
  
          return HttpResponse("You have succesfully unregistered for the meal")
      def form_invalid(self, form):
          return self.render_to_response(self.get_context_data(form=form))
  
      def dispatch(self,*args, **kwargs ):
  
          if self.request.user.is_active:
  
              context = super(ProfileView, self).dispatch( self.request, *args, **kwargs)
  
              return context                
          else:        
              return HttpResponseRedirect('%s?next=%s' % (settings.LOGIN_URL, self.request.path))
      def get_context_data( self, **kwargs):
              form=UnregisterMealForm(self.request.POST)
              meals = ['breakfast','lunch','dinner']
              context = {'meals' : meals , 'unregisterform': form}
  
              if form.is_valid():
                  select_date = request.POST['select_date']
                  select_meal = request.POST['meal']
                  context['recent'] = "You have succesfully unregistered    for "+ select_meal +" on " + select_date 
  
          return context
  </code></pre>
  
  <p>When I submit the form, it shows an error <code>Attribute Error 'UnregisterMealForm' object has no attribute 'user'</code></p>
  
  <p>Here is my <code>UnregisterMealForm</code></p>
  
  <pre><code>class UnregisterMealForm(forms.Form):
      MEALS = [('breakfast','breakfast'),('lunch','lunch'), ('dinner','dinner')]
      select_date = forms.DateField(widget=DateInput())
      meal = forms.CharField(widget=forms.Select(choices=MEALS, attrs={'class':'form-control', 'placehoder':'Choose the Meal' }))
  </code></pre>
  
  <p>Can anybody help me with this. If you need more information please tell me.</p>
  
  <p>Thanks in advance. 
  I m a novice in django.</p>