Hello Lekan. I have responded inline but my answer might not be a complete
fix.....

On May 5, 2016 4:56 PM, "Lekan Wahab" <[email protected]> wrote:
>
> Hello,
> Please, i have a model form in forms.py which am trying to validate and
update my database with. However, for some reason the form is not being
validated. I have tried everything i could think of. It just reloads the
page.
>
> views.py
>>
>> from django.shortcuts import render
>> from information.forms import ContactForm
>> from django.http import HttpResponse, HttpResponseRedirect
>>
>>
>> def index(request):
>>     form_class = ContactForm
>>     if request.method == 'POST':
>>         form = form_class()

The above line creates an empty form because you didn't supply anything as
the data argument therefore the is_valid method will never return True. You
need to instantiate it with your POST data. Try:
             form = form_class(request.POST)
>>         if form.is_valid():
>>             ###Dummy text to check validation
>>             return  HttpResponse('Done')
>>     return render(request, 'information/index.html', {'form':
form_class})
>>

{'form': form_class}
form_class is not an object. Perhaps you meant {'form': form}
>>
>> def complete(request):
>>     return HttpResponse("Thank you for contacting us")
>
>
> models.py
>
>>
>> from crispy_forms.helper import FormHelper
>> from django import forms
>> from django.core.exceptions import ValidationError
>> from django.forms import Form
>> from information.models import Contact
>> from crispy_forms.helper import FormHelper
>> from crispy_forms.layout import Layout,Fieldset, HTML
>> from crispy_forms.bootstrap import TabHolder,Tab
>>
>>
>> class ContactForm(forms.ModelForm):
>>     helper = FormHelper()
>>     helper.form_tag = False
>>     def __init__(self):
>>         super(ContactForm, self).__init__()
>>         for key in self.fields:
>>             self.fields[key].required= False
>>             self.fields[key].label = False
>>
>>
>>     class Meta:
>>         fields = '__all__'
>>         model =  Contact
>
>
> Thank you.
>
> --
> You received this message because you are subscribed to the Google Groups
"Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CAE6v7oeD7Qb_%2BJrhiOzRTiDJ%3DqEPAY56B86nuxdZnrv2EP%2BrdQ%40mail.gmail.com
.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BWjgXMLEmHKdtAWBA%2BsO7zPD9XGAggUPVXsU5beqg%3Dwb2Ax5Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to