def contact(request):
    if request.method == 'POST':
        f = ContactForm(request.POST)
        if f.is_valid():
            email = f.cleaned_data['email']
            ... #send email
            return HttpResponseRedirect(reverse('contact_success'))
   else:
         f=ContactForm()
         return render_to_response(
            'post_contact.html',
            { 'form':f },
            context_instance = RequestContext(request)
        )

I am still workong on the view code to send email when users submit
the form. The problem is that required field did not validate and
block the form submission. User is able to submit the form without
providing email which is a required field.

On Dec 31, 1:50 am, "Alex Koshelev" <daeva...@gmail.com> wrote:
> Please post here entire view code
>
>
>
> On Wed, Dec 31, 2008 at 8:18 AM, Chuck22 <cba...@gmail.com> wrote:
>
> > class ContactForm(forms.Form):
> >          email = forms.EmailField(required=True,
> >                             widget=forms.TextInput(attrs=
> > {'size':'30'}),
> >                            error_messages={'required':'Please fill
> > out your Email'})
> >          ...
>
> > in my form html file:
> > ...
> > label for="id_full_name">Your email address</label>
> >            {{ form.email.errors }}
> >            {{ form.email }}<br/>
> > ...
>
> > in my view:
> > def contact(request):
> >    if request.method == 'POST':
> >        f = ContactForm(request.POST)
> >        if f.is_valid():
> >            email = f.cleaned_data['email']
> >            ...
> >            return HttpResponseRedirect(reverse('contact_success'))
>
> > When user submit the contact form without fill out email field, the
> > form get submitted without displaying error message 'Please fill out
> > your Email'. Instead, I got error: The view app.views.contact didn't
> > return an HttpResponse object.
>
> > it seems f.is_valud return false, which is correct. But I think form
> > validation should kick in at this point and return error message to
> > {{ form.email.errors }} field in template. Why doesn't the validation
> > work? Did I miss anything?- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to