def get_ContactForm(request): # if this is a POST request we need to process the form data if request.method == 'POST': # create a form instance and populate it with data from the request: form = ContactForm(request.POST) # check whether it's valid: if form.is_valid(): #取得 form 包含的資料 username = form.cleaned_data.get('username'), email = form.cleaned_data.get('email'), comment = form.cleaned_data.get('comment'), # 在系統後台建立資料 obj = Request.objects.create( username=username, email=email, comment=comment, ) # redirect to a new URL: return HttpResponseRedirect('/Comment') # if a GET (or any other method) we'll create a blank form else: form = ContactForm() return render(request, 'Comment.html', {'form': form})
def contact(request): form = ContactForm(request.POST) print("*" * 10) print(form) print("*" * 10) if form.is_valid(): first_name = form.cleaned_data['first_name'] last_name = form.cleaned_data['last_name'] email = form.cleaned_data['email'] subject = form.cleaned_data['subject'] message = form.cleaned_data['message'] email_template = get_template('users/contact.html') email_content = email_template.render({ 'first_name': first_name, 'last_name': last_name, 'email': email, 'subject': subject, 'message': message, }) print("*" * 10) print(email_content) print("*" * 10) mail = EmailMultiAlternatives('New contact message', email_content, settings.EMAIL_HOST_USER, [email]) mail.content_subtype = 'html' mail.send()
def contact(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): topic = form.cleaned_data['topic'] message = form.cleaned_data['message'] sender = form.cleaned_data.get('sender', '*****@*****.**') send_mail( 'feedback from user, topic: %s sender:%s' % (topic, sender), message, '*****@*****.**', ['*****@*****.**']) return redirect('/thanks/') else: form = ContactForm() return TemplateResponse(request, 'contact.html', {'form': form})
def contact_us_view(request): form = ContactForm if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): print('Good Form!') print(f"first name: {form.cleaned_data['first_name']}") print(f"last name: {form.cleaned_data['last_name']}") return users(request) else: print('ERROR') return render(request, 'users/users_register.html', {'form': form})
def contact(request): if request.method=='POST': form=ContactForm(request.POST) if form.is_valid(): topic = form.cleaned_data['topic'] message = form.cleaned_data['message'] sender = form.cleaned_data.get('sender','*****@*****.**') send_mail( 'feedback from user, topic: %s sender:%s'%(topic,sender), message,'*****@*****.**',['*****@*****.**'] ) return redirect('/thanks/') else: form=ContactForm() return TemplateResponse(request,'contact.html',{'form':form})
def contact_view(request): contact_list = ContactApp.objects.all() if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): first_name = form.cleaned_data['first_name'] last_name = form.cleaned_data['last_name'] email = form.cleaned_data['email'] mobile = form.cleaned_data['mobile'] subject = form.cleaned_data['subject'] message = form.cleaned_data['message'] email_template = get_template('users/contact_email_send.html') email_content = email_template.render( { 'first_name': first_name, 'last_name': last_name, 'email': email, 'mobile': mobile, 'subject': subject, 'message': message, } ) mail = EmailMultiAlternatives( f'Boanca Ionut Silviu:{subject}', email_content, settings.EMAIL_HOST_USER, [email], (settings.EMAIL_HOST_USER, ) ) mail.content_subtype = 'html' mail.send() messages.success(request, 'Mesajul tau a fost trimis!') return HttpResponseRedirect(reverse('users:contact')) else: form = ContactForm() context = { 'form': form, 'contact_list': contact_list} return render(request, "users/contact.html", context)
def contact(request): if request.user.is_authenticated(): initial = { 'name': request.user.full_name, 'email': request.user.username, } form = ContactForm(initial=initial) else: form = ContactForm() if request.method == 'POST': form = ContactForm(data=request.POST) if form.is_valid(): email = form.cleaned_data['email'] name = form.cleaned_data['name'] message = form.cleaned_data['message'] body_context = { 'email': email, 'name': name, 'message': message, } send_and_log( subject='CoinSafe Support Message From %s' % name, body_template='admin/contact_form.html', to_merchant=None, to_email='*****@*****.**', to_name='CoinSafe Support', body_context=body_context, replyto_name=name, replyto_email=email, ) msg = _("Message Received! We'll get back to you soon.") messages.success(request, msg, extra_tags='safe') return HttpResponseRedirect(reverse_lazy('home')) return {'form': form}
def home(request): accomodation_total = Accomodation.objects.count() accomodation_comment_total = Comment.objects.count() users_total = User.objects.count() lastest = Accomodation.objects.all()[4:] context = { 'accomodation_total': accomodation_total, 'accomodation_comment_total': accomodation_comment_total, 'users_total': users_total, 'latest': lastest, 'form': ContactForm() } return render(request, 'openrider/home.html', context)
def contact_view(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): first_name = form.cleaned_data['first_name'] last_name = form.cleaned_data['last_name'] email = form.cleaned_data['email'] mobile = form.cleaned_data['mobile'] subject = form.cleaned_data['subject'] message = form.cleaned_data['message'] email_template = get_template('users/contact_email_send.html') email_content = email_template.render({ 'first_name': first_name, 'last_name': last_name, 'email': email, 'mobile': mobile, 'subject': subject, 'message': message, }) mail = EmailMultiAlternatives(f'Visit Romania:{subject}', email_content, settings.EMAIL_HOST_USER, [email], (settings.EMAIL_HOST_USER, )) mail.content_subtype = 'html' mail.send() return HttpResponseRedirect(reverse('users:contact')) else: form = ContactForm() return render(request, "users/contact.html", {'form': form})
def service(request): if request.method == 'GET': form = ContactForm() else: form = ContactForm(request.POST) if form.is_valid(): subject = form.cleaned_data['subject'] name = form.cleaned_data['name'] from_email = form.cleaned_data['email'] message = form.cleaned_data['message'] try: send_mail(name + ":" + subject, message, from_email, ['*****@*****.**']) except BadHeaderError: return HttpResponse('Invalid header found.') form.save() messages.success(request, 'Request sent!') return redirect('service') return render(request, 'service.html', {'form': form, 'title': 'Service'})