Thursday, June 30, 2011

Re: forms and form processing

Hi,
have you got email settings set in your settings.py?
What version of Django are you using?

Radovan
http://www.yau.sk

On 29. Jún, 00:23 h., "jay K." <jay.developer2...@gmail.com> wrote:
> Hello,
>
> I need to add a form on my django website
>
> so far this is what i have:
>
> in my models.py:
>
> .... import statements not shown here
>
> CONTACT_OPTIONS = (
>                                  ('skype video anruf','Skype Video-
> Anruf'),
>                                  ('skype anruf ','Skype Anruf'),
>                                  ('telefon','Telefon')
>                                 )
>
> class ContactForm(forms.Form):
>
>     #wann
>     date_input = forms.CharField(max_length=30, required=True) #,
> initial="MO-FR"
>     time_input = forms.CharField(max_length=30, required=True) # 14:00
> - 22:00
>
>     #wie
>     choice_options = forms.ChoiceField(widget=RadioSelect,
> choices=CONTACT_OPTIONS, required=True)
>
>     #contact
>     email = forms.EmailField(max_length=30, required=True)
>     telephone = forms.CharField(max_length=30, required=False)
>     skype = forms.CharField(max_length=30, required=False)
>
>     #comment
>     comment_text = forms.CharField(widget=forms.Textarea,
> required=False)
>
> my views.py
>
> from website.contact.models import ContactForm
> from django.shortcuts import render_to_response
> from django.template.context import RequestContext
> from django.http import HttpResponseRedirect, HttpResponse
> from django.core.mail import send_mail
>
> def contact(request):
>
>     if request.method == 'POST': # If the form has been submitted...
>         form = ContactForm(request.POST) # A form bound to the POST
> data
>
>         if form.is_valid(): # All validation rules pass
>             # Process the data in form.cleaned_data
>
>             subject = form.cleaned_data['subject']
>             message = form.cleaned_data['message']
>             sender = form.cleaned_data['sender']
>             cc_myself = form.cleaned_data['cc']
>
>             date_input = form.cleaned_data['date input']
>             time_input = form.cleaned_data['time input']
>             choice_options = form.cleaned_data['contact options']
>
>             telephone = form.cleaned_data['telefone']
>             email = form.cleaned_data['email'] # this is the sender's
> email
>             skype = form.cleaned_data['skype']
>
>             comment_text = form.cleaned_data['comment text']
>
>             """
>             recipients = ['joung.k...@lingua-group.org']
>             if cc_myself:
>                 recipients.append(sender)
>             """
>            #subject
>             send_mail('subject', 'message', 'myem...@myemail.com',
> ['myem...@myemail.com', email], fail_silently=False)
>
>             return HttpResponseRedirect('/danke/')
>
>     else:
>         form = ContactForm() # An unbound form
>
>     return render_to_response('beratungstermin.html', {'form': form},
> context_instance=RequestContext(request))
>
> And on the website I have all the fields inside the form tag
> <form action="/mythankyoupage" method="post">
> {{ forms.as_p }}
> </form>
>
> What I want to do basically is to add the fields for name, email, tel,
> some of them being compulsory, so the form should not be processed if
> there is some info. missing.
>
> I also want to receive a confirmation email whenever a user sends
> information through the page, to my "myem...@myemail.com" (this is not
> working on my code either), and a "CC" button if the user wants a copy
> of his/her own message.
>
> Thanks
>
> Let me know if you need any details
>
> PS: i copied most of the code from the official django tutorial athttps://docs.djangoproject.com/en/dev/topics/forms/?from=olddocs, but
> somehow I do not receive any emails after hitting the submit button.
> Also, even if I declared in my views.py that some fields are
> "required=True", I can still hit the send button with no error
> messages for those unfilled textfields.

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment