def submit_form(request): errors=[] if request.method == 'POST': if not request.POST.get('name', ''): errors.append('Enter your name.') if not request.POST.get('email', ''): errors.append('Enter a valid email address.') if request.POST.get('email') and '@' not in request.POST['email']: errors.append('Enter a valid e-mail address.') if not request.POST.get('subject', ''): errors.append('Enter a subject.') if not request.POST.get('message', ''): errors.append('Enter a message.') if not request.user.is_authenticated() and not request.POST.get('answer')==ans: errors.append('Enter correct answer to the question') if request.user.is_authenticated(): name = request.user.get_full_name() email = request.user.email else: name = request.POST['name'] email = request.POST['email'] if not errors: cform = contactform() cform.name = name cform.email = email cform.phone = request.POST['phone'] cform.subject = request.POST['subject'] cform.message = request.POST['message'] subject = "Contact %s : %s" %(request.POST['email'], request.POST['subject']) t = get_template('contactus/contactmail.html') tc = get_template('contactus/contactmail.txt') c = RequestContext(request, {'name': name, 'phone':request.POST['phone'], 'subject':request.POST['subject'], 'message':request.POST['message'], 'email':email, }) message = t.render(c) messagec = tc.render(c) email = EmailMultiAlternatives(subject, messagec, cform.email, to=[settings.DEFAULT_TO_EMAIL], headers = {'Reply-To': cform.email}) email.attach_alternative(message, "text/html") email.send() cform.save() return HttpResponseRedirect('/contactus/thanks/') t = get_template('contactus/contactus.html') c = RequestContext (request, { 'errors': errors, 'name': name, 'phone' : request.POST.get('phone',''), 'subject': request.POST.get('subject', ''), 'message': request.POST.get('message', ''), 'email': email, 'ques':ques, }) html = t.render(c) return HttpResponse(html)
def submit_form(request): errors = [] if request.method == 'POST': if not request.POST.get('name', ''): errors.append('Enter your name.') if not request.POST.get('email', ''): errors.append('Enter a valid email address.') if request.POST.get('email') and '@' not in request.POST['email']: errors.append('Enter a valid e-mail address.') if not request.POST.get('subject', ''): errors.append('Enter a subject.') if not request.POST.get('message', ''): errors.append('Enter a message.') if not request.user.is_authenticated() and not request.POST.get( 'answer') == ans: errors.append('Enter correct answer to the question') if not errors: cform = contactform() cform.name = request.POST['name'] cform.email = request.POST['email'] cform.phone = request.POST['phone'] cform.subject = request.POST['subject'] cform.message = request.POST['message'] cform.save() EmailMessage( request.POST['subject'], request.POST['message'], request.POST.get('email', '*****@*****.**'), ['*****@*****.**'], ) return HttpResponseRedirect('/contactus/thanks/') t = get_template('contactus/contactus.html') if request.user.is_authenticated(): name = request.user.get_full_name() email = request.user.email else: name = request.POST['name'] email = request.POST['email'] c = RequestContext( request, { 'errors': errors, 'name': name, 'phone': request.POST.get('phone', ''), 'subject': request.POST.get('subject', ''), 'message': request.POST.get('message', ''), 'email': email, 'ques': ques, }) html = t.render(c) return HttpResponse(html)
def submit_form(request): errors=[] if request.method == 'POST': if not request.POST.get('name', ''): errors.append('Enter your name.') if not request.POST.get('email', ''): errors.append('Enter a valid email address.') if request.POST.get('email') and '@' not in request.POST['email']: errors.append('Enter a valid e-mail address.') if not request.POST.get('subject', ''): errors.append('Enter a subject.') if not request.POST.get('message', ''): errors.append('Enter a message.') if not request.user.is_authenticated() and not request.POST.get('answer')==ans: errors.append('Enter correct answer to the question') if not errors: cform = contactform() cform.name = request.POST['name'] cform.email = request.POST['email'] cform.phone = request.POST['phone'] cform.subject = request.POST['subject'] cform.message = request.POST['message'] cform.save() EmailMessage( request.POST['subject'], request.POST['message'], request.POST.get('email', '*****@*****.**'), ['*****@*****.**'], ) return HttpResponseRedirect('/contactus/thanks/') t = get_template('contactus/contactus.html') if request.user.is_authenticated(): name = request.user.get_full_name() email = request.user.email else: name = request.POST['name'] email = request.POST['email'] c = RequestContext (request, { 'errors': errors, 'name': name, 'phone' : request.POST.get('phone',''), 'subject': request.POST.get('subject', ''), 'message': request.POST.get('message', ''), 'email': email, 'ques':ques, }) html = t.render(c) return HttpResponse(html)