def contact(demo): form = ContactForm() form2 = DemoForm() demo = False if demo == '0' else True if request.method == 'POST': if form and form.validate() == False and demo == False or form2 and form2.validate() == False and demo == True: error_message = gettext('All fields are required and e-mail must be valid') flash(error_message) return render_template('contact.html', **locals()) elif form2 and form2.validate() == True: msg = Message("Demo Request", sender='*****@*****.**', recipients=['*****@*****.**']) msg.body = """ From: %s <%s> %s """ % (form.name.data, form.email.data, form.message.data) mail.send(msg) success = True return render_template('contact.html', **locals()) elif form and form.validate() == True: msg = Message(form.subject.data, sender='*****@*****.**', recipients=['*****@*****.**']) msg.body = """ From: %s <%s> %s """ % (form.name.data, form.email.data, form.message.data) mail.send(msg) success = True return render_template('contact.html', **locals()) else: return render_template('contact.html', **locals()) elif request.method == 'GET': return render_template('contact.html', **locals())
def contact(): form=ContactForm(request.form) if request.method=='POST': if form.validate()==False: print form.validate() flash('All fields are required') return render_template('contact.html',form=form) else: return render_template('success.html') elif request.method=='GET': return render_template('contact.html',form=form)
def search_products(): form = ContactForm() if request.method == 'POST': print "==== print:" print form.validate() if form.validate() == False: flash('All fields are required.') return render_template('search.html', form=form) else: msg = Message(form.senderssubject.data, sender='*****@*****.**', recipients=['*****@*****.**']) msg.html = """ <b>From:</b> <i>%s</i> <br> <b>Email-id:</b> <i>%s</i> <br> <b>Message:</b> <i>%s</i>""" \ % (form.sendersname.data, form.sendersemail.data, form.sendersmessage.data) mail.send(msg) form = ContactForm() return render_template('search.html', form=form, success=True) elif request.method == 'GET': try: if 'searchKeyword' in request.args: keyword = request.args['searchKeyword'] client = pymongo.MongoClient(MONGODB_URI) db = client.get_default_database() prod_details = db['product_details'] cursor = prod_details.find({'prodCategory': keyword}) # { '$in': [ '/ keyword /' ] } #.sort('prodId', 1) listProd = [] # print ('prodId: %d,Prod Name: %s , Prod Desc: %s.' % (doc['prodId'], doc['ProdName'], doc['ProdDesc'], doc['ProdCount'])) for doc in cursor: print doc['prodName'] #print ('ProdId: %d,Prod Name: %s , Prod Desc: %s, ProdCount: %d' % (doc['ProdId'], doc['ProdName'], doc['ProdDesc'], doc['ProdCount'])) listProd.append(doc) # print str(keyword) # print listProd client.close() return render_template("search.html", form=form, status="Search Successful!", item2=listProd, itemlist=listProd, count=max(len(listProd), 0)) else: return render_template( 'search.html', form=form ) #, status = "Rendering Page Successfully!", item2 = NULL, itemlist = NULL ) except: e = sys.exc_info()[0] print "exception: " + e
def contact(): info['current_tab'] = 'contact' form = ContactForm() if request.method == "POST" and form.validate(): i = Inquiry(email=form.email.data, inquiry=form.inquiry.data, name=form.name.data) db.session.add(i) db.session.commit() flash("Takk for din henvendelse!", category="success") elif request.method == "POST" and not form.validate(): flash("Pass på at du har fylt ut kontaktskjemaet riktig.", category="warning") return render_template('contact.html', form=form, info=info)
def index(): form = ContactForm(request.form) if request.method == 'POST' and form.validate() == True: msg = Message(subject='Web Mail', sender=form.email.data, recipients=['*****@*****.**']) msg.body = """ From: %s <%s> %s """ % (form.name.data, form.email.data, form.message.data) mail.send(msg) return redirect(url_for('index_sent')) elif request.method == 'POST' and form.validate() == False: return render_template('index-error.html', form=form) elif request.method == 'GET': return render_template('index.html', form=form)
def post(self): form = ContactForm(self) params = { 'form': form, } self.response.write(form.validate()) if form.validate(): contact = Contact( name=self.request.get('name'), email=self.request.get('email'), subject=self.request.get('subject'), body=self.request.get('body'), ) contact.put() self.render_response('contact.html', **params)
def create(): form = ContactForm() if form.validate() is False: for error_type in form.errors: if form.errors[error_type][0] in dictionary(): form.errors[error_type][0] = dictionary()[ form.errors[error_type][0]] return render_template('contact/index.html', form=form, action=url_for('contact.create')) else: contact = Form() contact.name = form.name.data contact.email = form.email.data contact.subject = form.subject.data contact.message = form.message.data contact.postage_date = datetime.now().strftime('%Y-%m-%d %H:%M:%S') message_tpl = render_template('contact/message_template.html', contact=contact) db.session.add(contact) db.session.commit() send_mail("Contato - DataViva", [admin_email], message_tpl) message = gettext( "Your message has been sent successfully. We will soon get back to you." ) flash(message, 'success') return redirect(url_for('contact.create'))
def contact(): form = ContactForm() if request.method == 'POST': if form.validate() == False: flash('All fields are required.') return render_template('contact.html', form=form) else: reviews = request.form['message'] y, prob = classify(reviews) print(y, prob) if (y == 'Spam'): flash('Message is spam') return render_template('spam.html', form=form) else: msg = Message(form.subject.data, sender='nikhilbdg@gmail', recipients=['*****@*****.**']) msg.body = """ From:%s:%s; %s """ % (form.name.data, form.email.data, form.message.data) mail.send(msg) return render_template('contact.html', success=True) else: return render_template('contact.html', form=form)
def edit_contact(username): usuario = Usuario.objects.get(username=username) user_json=usuario uuu = [{'nombre':'nombre','username':'******'}] post = Usuario.objects.get_or_404(username=username) form = ContactForm(request.form,user_json) if request.method == 'POST': if form.validate() == False: flash('All fields are required.') return render_template('contact.html', form=form, data_type="Usuarios", action="Editar") else: usuario.nombre=form.nombre.data usuario.username=form.username.data usuario.password=form.password.data usuario.perfil=form.perfil.data # usuario.grupos=[{'nombre':'test1','horario':'LLLLLLL'}] usuario.save() # Usuario(nombre=form.nombre.data,apellido=form.lastname.data ,username=form.username.data, password=form.password.data,perfil=form.perfil.data).save() # Insert # return form.nombre.data + " " +form.username.data return list_users() elif request.method == 'GET': print 'GET' print form.errors return render_template('contact.html', form=form, data_type="usuarios", action="Editar")
def contact(): FlaskForm = ContactForm() if request.method == 'POST': if FlaskForm.validate() == False: flash('All fields are required') return render_template('contact.html', form=FlaskForm) else: msg = Message(FlaskForm.subject.data, sender='*****@*****.**', recipients=['*****@*****.**']) msg.body = """ From: %s <%s> %s """ % (FlaskForm.name.data, FlaskForm.email.data, FlaskForm.message.data) mail.send(msg) flash( 'Thank you for messaging me, I will get back to you as soon as possible!' ) return render_template('contact.html', form=FlaskForm) elif request.method == 'GET': return render_template('contact.html', form=FlaskForm)
def contact_us(): form = ContactForm() if request.method == 'POST': if form.validate() == False: flash('All fields are required.') return render_template('contact-us.html', form=form) else: msg = Message( form.reason.data + ': ' + form.subject.data, sender='*****@*****.**', recipients=['*****@*****.**', form.email.data]) msg.body = """ Dear %s, you are receiving this email because you, or someone pretending to be you filled out our contact form on NeighborZ (https://xXTechGodSquadXx.pythonanywhere.com). If this was not you, please respond to this email saying that this was not you. Thanks, NeighborZ Staff. --- From: %s <%s> Reason: %s Body: %s """ % (form.email.data, form.name.data, form.email.data, form.reason.data, form.message.data) mail.send(msg) return '<h3>Message submitted, redirecting back to home page in 3 seconds. If your browser does not support auto redirecting, <a href="/../"> click here </a> </h3> <meta http-equiv="Refresh" content="3; url=/../" />' elif request.method == 'GET': return render_template('contact-us.html', form=form)
def contact(): form = ContactForm() if request.method == 'POST': if form.validate() == False: flash('All fields are required.') return render_template('contact.html', title = 'Contact', form = form) else: msg = Message(form.subject.data, sender='*****@*****.**', recipients=['*****@*****.**']) msg.body = """ From: %s <%s> %s """ % (form.name.data, form.email.data, form.message.data) mail.send(msg) return render_template('contact.html', title = 'Contact', success = True, form = form) elif request.method == 'GET': return render_template('contact.html', title = 'Contact', form = form)
def contact(): from forms import ContactForm if request.method == 'POST' and is_ajax(): form = ContactForm(as_multidict(request.json), csrf_enabled=False) else: form = ContactForm(csrf_enabled=True) message = "Thanks for your feedback" if request.method == 'POST': if form.validate(): from cdw import emailers emailers.send_contact(**form.to_dict()) if request.is_xhr or 'application/json' in request.headers[ 'Accept']: return jsonify(message=message) flash(message) else: print form.errors if (request.is_xhr or ('Accept' in request.headers.keys() and 'application/json' in request.headers['Accept'])): return jsonify(form.errors) return render_template('contact.html', section_selector="contact", page_selector="index", form=form)
def contact(): """ Page with a simple contact form :return: json object with template data or rendered template """ form = ContactForm(request.form) is_ajax = request.headers.get('X-Requested-With') == 'XMLHttpRequest' if request.method == 'POST': if form.validate(): name, email, message = form.name.data, form.email.data, form.message.data message = format_mail(name, email, message) msg = Message('[Code Speculation] Contact', sender="*****@*****.**", recipients=["*****@*****.**"]) msg.body = message mail.send(msg) form = ContactForm() flash_msg = 'Thank you' template = render_template('contact.html', form=form, ajax=is_ajax, flash_msg=flash_msg) return jsonify({'flash_msg': flash_msg}) if is_ajax else template else: template = render_template('contact.html', form=form, ajax_errors=is_ajax, ajax=is_ajax) return jsonify({'errors': template}) if is_ajax else template template = render_template('contact.html', form=form, ajax=is_ajax) return jsonify( {'data': template, 'title': 'Code Speculations - Contact Ana'}) \ if is_ajax else template
def dispatch_request(self): form = ContactForm() if request.method == 'POST': if form.validate() is False: return render_template('contact/contact.html', form=form) else: msg = Message(form.subject.data, sender=(form.name.data, form.email.data), recipients=["*****@*****.**"]) msg.html = """ <b>De:</b> %s <i>%s</i> <h4><b>Mensaje:</b></h4> <p>%s</p> """ % (form.name.data, form.email.data, form.message.data) msg.body = """ De: %s <%s> Mensaje: %s """ % (form.name.data, form.email.data, form.message.data) mail.send(msg) return render_template('contact/contact.html', success=True) elif request.method == 'GET': return render_template('contact/contact.html', form=form)
def edit_contact(key_str): form_data = bottle.request.forms form = ContactForm(form_data.decode()) if form.validate(): # Check that a photo was uploaded if 'photo' in bottle.request.files: photo = bottle.request.files['photo'] parsed_ct = parse_options_header(photo.content_type) blob_key = parsed_ct[1]['blob-key'] photo_url = get_serving_url(blob_key, size=32, crop=True) else: # Set to None so that we don't get any funny business # on the call to create_contact photo_url = None blob_key = None # Retrieve contact's Datastore key key = ndb.Key(urlsafe=key_str) # Delete the record key.delete() # Retrieve the user's Datastore key string and create a contact linked # to that key user_key_str = bottle.request.session['user_key_str'] key = create_contact(form, user_key=ndb.Key(urlsafe=user_key_str), photo_url=photo_url, blob_key=blob_key) return refresh_path('/') else: return get_contact(key_str, form=form, upload_url=blobstore.create_upload_url("/edit/" + key_str))
def contact_form(): form = ContactForm(request.form) msg = {} if request.method == 'POST' and form.validate(): if form.nospam.data == '2': if form.message.data != "8": print "WARN: bot attempted usage on contact form!" warned = warn_admin(request, mail) if warned['succ_code'] != 0: print "there was an error emailing the report" abort(403) subject = form.subject.data message = form.emessage.data sender = form.sender.data msg = dict(sender=sender, subject=subject, message=message) ##_log_mail(msg) ret = mail_admin(msg, mail) if ret['succ_code'] != 0: flash("There was an error sending this message") return redirect(url_for('contact_success')) else: flash("Message: %(subject)s was sent successfully by %(email)s" %\ { "subject" : msg['subject'], "email" : msg['sender'], }) print "successfully sent to SMTP" return redirect(url_for('contact_success')) return render_template('base.html', msg=msg, form=form)
def create(): form = ContactForm() if form.validate() is False: for error_type in form.errors: if form.errors[error_type][0] in dictionary(): form.errors[error_type][0] = dictionary()[form.errors[error_type][0]] return render_template('contact/index.html', form=form, action=url_for('contact.create')) else: contact = Form() contact.name = form.name.data contact.email = form.email.data contact.subject = form.subject.data contact.message = form.message.data contact.postage_date = datetime.now().strftime('%Y-%m-%d %H:%M:%S') message_tpl = render_template('contact/message_template.html', contact=contact) db.session.add(contact) db.session.commit() send_mail("Contato - DataViva", [admin_email], message_tpl) message = gettext("Your message has been sent successfully. We will soon get back to you.") flash(message, 'success') return redirect(url_for('contact.create'))
def contact(): form = ContactForm() if request.method == "POST": if form.validate() == False: flash('All fields are required.') return render_template('contact.html', form=form, omEmail=omEmail, omPhone=omPhone) else: msg = Message('Message from your OMOKC.com' + form.name.data, sender='*****@*****.**', recipients=['*****@*****.**']) msg.body = """ From: %s <%s>, %s """ % (form.name.data, form.email.data, form.message.data) mail.send(msg) return render_template('contact.html', success=True, omEmail=omEmail, omPhone=omPhone) elif request.method == 'GET': return render_template('contact.html', form=form, omEmail=omEmail, omPhone=omPhone)
def getsupport(): form = ContactForm() if request.method == 'POST': if form.validate() == False: flash('All fields are required') return render_template('getsupport.html', loggedin=True, form=form, user=current_user.username) else: msg = Message(form.subject.data, sender=['*****@*****.**'], recipients=['*****@*****.**']) msg.body = """ From: %s <%s> %s """ % (form.name.data, form.email.data, form.message.data) mail.send(msg) return render_template('getsupport.html', success=True, loggedin=True, user=current_user.username) elif request.method == 'GET': return render_template('getsupport.html', loggedin=True, form=form, user=current_user.username)
def Contact(): form = ContactForm() if request.method == 'POST': if form.validate() == False: flash('All fields are required.') return render_template('template_oop.html', title='Contact', form=form) else: msg = Message(form.subject.data, sender='*****@*****.**', recipients=['*****@*****.**']) msg.body = """ From: %s <%s> %s """ % (form.name.data, form.email.data, form.message.data) with sqlite3.connect(app.config['DATABASE']) as con: cur = con.cursor() cur.execute( "INSERT INTO contact_table (name, email, subject, comment) VALUES (?,?,?,?)", (form.name.data, form.email.data, form.subject.data, form.message.data)) con.commit() mail.send(msg) return render_template('template_oop.html', title='Contact', success=True) elif request.method == 'GET': return render_template('template_oop.html', title='Contact', form=form)
def mainsite(): """This function renders the main website. The function evaluates the contact form and gets poem data for both current and archive display from a database when loading the site. """ # define standard display contact_form = ContactForm() contact_form_success = False jump_to_contact = False if request.method == 'POST': if not contact_form.validate(): # contact form validation failed jump_to_contact = True else: # contact form validation succeeded, send email msg = Message('Neue Nachricht von Tagespoet.de!', sender=app.config['MAIL_USERNAME'], recipients=[app.config['MAIL_RECIPIENT']]) msg.body = """ Von: %s <%s> %s """ % (contact_form.name.data, contact_form.email.data, contact_form.message.data) mail.send(msg) contact_form_success = True jump_to_contact = True # get poem of the day cur_poem = mongo.db.poems.find_one({}, sort=[('date', flask_pymongo.DESCENDING)]) if cur_poem is not None: # poem found cur_poem_ret = make_poem_html(cur_poem['poem'], 'poemline') cur_poem_render_ret = 1 else: # no poem found, return empty values # TODO: Implement error handling (logging, sending out maintenance request email) cur_poem_ret = '' cur_poem_render_ret = 0 # organize archive first_poem = mongo.db.poems.find_one({}, sort=[('date', flask_pymongo.ASCENDING)]) now = datetime.now() yesterdays_date = datetime(now.year, now.month, now.day, 0, 0, 1) + timedelta(hours=6) - timedelta(days=1) last_poem = mongo.db.poems.find_one({'date': {'$lte': yesterdays_date}}, sort=[('date', flask_pymongo.DESCENDING)]) todays_date = datetime.today() + timedelta(hours=6) return render_template('index.htm', todays_date=todays_date.strftime("%d.%m.%YYYY"), cur_poem_render=cur_poem_render_ret, cur_poem=cur_poem_ret, first_poem_date=first_poem['date'].strftime('%d.%m.%Y'), last_poem_date=last_poem['date'].strftime('%d.%m.%Y'), last_poem_date_heading=last_poem['date'].strftime("%Y-%m-%dT%H:%M:%S"), last_poem=make_poem_html(last_poem['poem'], 'poemarchiveline'), last_keywords=make_keyword_html(last_poem['keywords']), contact_form=contact_form, contact_form_success=contact_form_success, jump_to_contact=jump_to_contact)
def contact(): form = ContactForm() if request.method == "POST": if form.validate() == False: flash('All fields are required.') return render_template('contact.html', form=form, contact="selected") else: msg = Message(form.subject.data, sender='*****@*****.**', recipients=['*****@*****.**']) msg.body = """ From: {0} <{1}> {2} """.format(form.name.data, form.email.data, form.message.data) mail.send(msg) return render_template('contact.html', success=True, contact="selected") elif request.method == "GET": return render_template('contact.html', form=form, contact="selected")
def dispatch_request(self): form = ContactForm() if request.method == "POST": if form.validate() is False: return render_template("contact/contact.html", form=form) else: msg = Message( form.subject.data, sender=(form.name.data, form.email.data), recipients=["*****@*****.**"] ) msg.html = """ <b>De:</b> %s <i>%s</i> <h4><b>Mensaje:</b></h4> <p>%s</p> """ % ( form.name.data, form.email.data, form.message.data, ) msg.body = """ De: %s <%s> Mensaje: %s """ % ( form.name.data, form.email.data, form.message.data, ) mail.send(msg) return render_template("contact/contact.html", success=True) elif request.method == "GET": return render_template("contact/contact.html", form=form)
def contact(): contactForm = ContactForm(csrf_enabled=False) #if contact form submitted if contactForm.send.data: #Clean and verify input if contactForm.validate() == False: flash(VALIDATION_FAIL) return render_template('contact.html', contactForm=contactForm, lines=get_lines()) else: try: name = contactForm.name.data except: name = '' try: sender = contactForm.email.data except: sender = '' try: message = contactForm.message.data except: message = '' send_email("Contact " + name, sender, [ADMIN], message, '') return render_template('contact.html', banner=BANNER, contact=get_contact(), contactForm=contactForm, lines=get_lines(), referrer=request.referrer)
def contact(): form = ContactForm() if request.method == "POST": if form.validate() == False: flash("All fields are required.") return render_template("contact.html", form=form) else: msg = Message(form.subject.data, sender="*****@*****.**", recipients=["*****@*****.**"]) msg.body = """ From: %s <%s> Affiliation: %s Field(s) of Interest: %s Message: %s """ % ( form.name.data, form.email.data, form.affiliation.data, form.fieldofinterest.data, form.message.data, ) mail.send(msg) return render_template("contact_success.html") elif request.method == "GET": return render_template("contact.html", form=form)
def new_contact(): if 'email' not in session: return redirect(url_for('login')) form = ContactForm() if request.method == 'POST': if form.validate() is False: return render_template('newcontact.html', form=form) else: email = session['email'] user = db_session.query(User).filter_by(email=email).first() contacts = Contact() contacts.UserId = user.id if form.first_name.data and form.last_name.data: contacts.name = form.first_name.data+' '+form.last_name.data if form.email.data: contacts.email = form.email.data if form.phone_number: contacts.phoneNumber = form.phone_number.data if form.address.data: contacts.address = form.address.data db_session.add(contacts) db_session.commit() return redirect(url_for('contacts')) elif request.method == 'GET': return render_template('newcontact.html', form=form)
def contact(): form = ContactForm() if request.method == 'POST': #submitbutton if form.validate() == False: flash('All fields are required.') #error message return render_template('contact.html', form=form) #still stay at the page else: #start composing a new message. msg = Message(form.subject.data, sender='*****@*****.**', recipients=['*****@*****.**' ]) #a "from" address, and a "to" address msg.body = """ From: %s <%s> %s """ % ( form.name.data, form.email.data, form.message.data ) #format the mail - we write the email itself. We include the user's name, email and message mail.send(msg) #message send return render_template('contact.html', success=True) elif request.method == 'GET': return render_template('contact.html', form=form)
def contactme(): form = ContactForm(request.form) if request.method == 'POST': name=request.form['name'] comment=request.form['comment'] email=request.form['email'] logging.debug('%s %s %s' % (name, email, comment)) if form.validate(): try: flash('Thanks for contacting me, %s !' % name) sender_address = app.config['EMAIL_ADDRESS_FROM'] mail.send_mail(sender=sender_address, to=app.config['CONTACT_ME_SEND_TO'], subject=('[jkgarage-home] Message from %s<%s>' % (name, email)), body=comment) except Exception as e: print (traceback.format_exc()) logging.error(traceback.format_exc()) else: flash('Error: %s' % form.errors) logging.error('Error: %s' % form.errors) return render_template('contactme.html', form=form)
def contact1(): form = ContactForm() if request.method == 'POST': if form.validate() == False: flash('All fields are required.') return render_template('contact1.html', form=form) else: msg = Message(form.subject.data, sender='*****@*****.**', recipients=['*****@*****.**']) msg.body = """ From: %s <%s> Subject: %s %s """ % (form.name.data, form.email.data, form.subject.data, form.message.data) mail.send(msg) return render_template('contact1.html', success=True) elif request.method == 'GET': return render_template('contact1.html', form=form) '''if request.method == 'POST':
def contact(): form = ContactForm() if request.method == "GET": return render_template('contact.html', form=form, current='contact') elif request.method == "POST": if not form.validate(): return render_template('contact.html', form=form, current='contact') else: pass msg = Message("[Melmelboo] %s" % form.name.data, sender=form.email.data, reply_to=form.email.data, recipients=[ '*****@*****.**', '*****@*****.**' ]) msg.body = """ From: %s <%s> Website: %s %s """ % (form.name.data, form.email.data, form.website.data, form.message.data) mail.send(msg) return render_template('contact.html', form=form, success=True, current='contact')
def result(): if request.method == 'GET': form = ContactForm(request.args) if form.validate(): query = [] if form.email: query.append(('email', form.email.data)) if form.phone: query.append(('phone', form.phone.data.replace('+',''))) if form.twitter: query.append(('twitter', form.twitter.data)) if form.facebook: query.append(('facebookUsername', form.facebook.data)) userdata = aggregate_data(query) return render_template('results/get_results.html', ud=userdata) elif request.method == 'POST': if request.files.get('file'): # get emails from file, if one was uploaded batch_data = emails_from_file(request.files.get('file')) else: batch_data = request.form.get('batch_data') if batch_data: batch_data = batch_data.replace('facebook', 'facebookUsername').split(',') for i in range(len(batch_data)): batch_data[i] = tuple(batch_data[i].split(':')) if batch_data: response = batch_lookup(batch_data, request.url_root + url_for('webhook')[1:]) else: response = ["Nothing to process"] return render_template('results/post_results.html', response=response)
def contact(): form = ContactForm() if request.method == "POST": if form.validate() == False: flash('All fields are required') return render_template("/contact.html", form=form) else: msg = Message("Contact from " + form.first_name.data + " " + form.last_name.data, sender=form.email.data, recipients=['*****@*****.**']) msg.body = """From: %s %s <%s>\nOccasion: %s\nMessage: %s""" % ( form.first_name.data, form.last_name.data, form.email.data, form.occasion.data, form.message.data) #form.attachment.save('uploads/'+form.attachment.data) #with app.open_resource(form.attachment.data) as fp: #file = os.path.abspath(form.attachment.data) #filename = secure_filename(file) #path = app.config["UPLOAD_FOLDER"] #shutil.copy(file, path) #msg.attach(file, file.read()) mail.send(msg) return render_template("/contact.html", form=form) elif request.method == "GET": return render_template("/contact.html", form=form)
def contact(): form = ContactForm() if request.method == 'POST': if form.validate() == False: flash('All fields are required.') return render_template('contact-us.html', form=form, page="contact") else: msg = Message(form.subject.data, sender=config.MailData.FROM, recipients=config.MailData.TO) msg.body = """ From: %s <%s> %s """ % (form.name.data, form.email.data, form.message.data) try: mail.send(msg) return render_template('contact-us.html', success=True, page="contact") except: form = ContactForm() return render_template('contact-us.html', form=form, error=True, page="contact") elif request.method == 'GET': return render_template('contact-us.html', form=form, success=None, page="contact")
def contact(): contactform = ContactForm() if request.method == 'POST': if contactform.validate() == False: flash('All fields are required.') return render_template('contact.html', contactform=contactform) else: try: # The connection will be closed for you as soon as execution leaves the <with> block, no matter by what route. with connection.cursor() as cursor: # Create a new recrod name = contactform.name.data email = contactform.email.data goodatfields = contactform.goodatfields.data comment = contactform.comment.data wechat = contactform.wechat.data # sql = 'INSERT INTO sqdict (word, meaning) VALUES (%s, %s)' sql = 'INSERT INTO contacttb (name, email, goodatfields, comment, wechat) VALUES (%s, %s, %s, %s, %s)' cursor.execute(sql, (name, email, goodatfields, comment, wechat)) # execute 别忘了 connection.commit() cursor.close() return 'success' except Exception as e: traceback.print_exc(limit=1, file=sys.stdout) else: return render_template('contact.html', contactform=contactform)
def home(): storage = Storage() items_to_validate = storage.items if request.method == 'POST': form = ContactForm(request.form) if form.validate(): qr = qrcode.QRCode( version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=5, border=4, ) qr.add_data(form.data['title']) qr.make(fit=True) img = qr.make_image() buff = StringIO.StringIO() img.save(buff, 'GIF') encoded_data = base64.b64encode(buff.getvalue()) model = BlogPostModel(datetime.datetime.now(),form.data['title'],form.data['text'],encoded_data) items_to_validate.append(model) else: form = ContactForm() return render_template('home.html', form=form, items=items_to_validate, )
def contact(): form = ContactForm() if request.method == 'POST': if form.validate() == False: flash('All fields are required.') return render_template('contact.html', form=form) else: #msg = Message(form.subject.data, sender='*****@*****.**', recipients=['*****@*****.**']) #msg.body = """ #From: %s <%s> #%s #""" % (form.name.data, form.email.data, form.message.data) #mail.send(msg) entry = Entry() form.populate_obj(entry) entry.token = os.urandom(24).encode('hex') #uuid.uuid4().hex) db.session.add(entry) try: db.session.commit() except exc.SQLAlchemyError: flash('All fields are required.') return render_template('contact.html', form=form, sqlerr="duplicate name/email") token = request.url_root + "search?token=" + entry.token print "token=", token return render_template('contact.html', success=True, qrcode_content=token, token=entry.token) elif request.method == 'GET': return render_template('contact.html', form=form)
def create(): form = ContactForm() if form.validate() is False: return Response(status=400, mimetype='application/json') else: contact = Form() contact.name = form.name.data contact.email = form.email.data contact.subject = form.subject.data contact.message = form.message.data contact.postage_date = datetime.now().strftime('%Y-%m-%d %H:%M:%S') message_tpl = render_template('contact/message_template.html', contact=contact) db.session.add(contact) db.session.commit() send_mail("Mensagem recebida via página de Contato", ["*****@*****.**"], message_tpl) message = gettext( "Your message has been sent successfully. We will soon get back to you." ) return Response(message, status=200, mimetype='application/json')
def contact(): form = ContactForm() # if server receives POST request, function form.validate() should capture the form field data and check if it's valid if request.method == 'POST': # if any validation check fails, form.validate() will be False. if form.validate() == False: # flash message occurs flash('All fields are required.') # after flash message template will be returned return render_template('contact.html', form=form) # esle statement if no validation error occurs else: msg = Message(form.subject.data, sender='*****@*****.**', recipients=['*****@*****.**']) # send the email using % as a formatting operator (users name, email and message) msg.body = """ From: %s <%s> %s """ % (form.name.data, form.email.data, form.message.data) # send email via mail.send(msg) mail.send(msg) # return template with sucess message return render_template('contact.html', success=True) # return template with contact form (GET request) elif request.method == 'GET': return render_template('contact.html', form=form)
def contact(): db = get_db() form = ContactForm() if request.method == 'POST': if form.validate() == False: flash('All fields are required.', 'error') return render_template('contact.html', form=form) else: try: db.execute( 'insert into entries (name, fvcolor, pet) values (?, ?, ?)', [ request.form['name'], request.form['fvcolor'], request.form['pet'] ]) except sqlite3.Error as e: flash('Please do not repeat. New entry was not posted', 'error') return redirect(url_for('contact')) db.commit() flash('Thank you. New entry was successfully posted') return redirect(url_for('contact')) elif request.method == 'GET': return render_template('contact.html', form=form)
def contact(): form = ContactForm( ) #Setting the Form as the class created called ContactForm in forms.py if request.method == 'POST': #If this page was requested with post, meaning that the form was submitted if form.validate( ) == False: #If the form fails the validation fucntion, re-render the template and error messages are shown flash('All fields are reqired') return render_template('contact.html', form=form) else: #The following lines of code, send 2 different emails, one to me (as an admin) and the other to whatever email was passed in the form msg = Message(form.subject.data, sender='*****@*****.**', recipients=['*****@*****.**']) msg.body = """ NEW MESSAGE : %s From: %s <%s> """ % ( form.message.data, form.name.data, form.email.data ) #Sends the admin an email with the contents of the contact form mail.send(msg) msg = Message('Your recent Enquiry', sender='*****@*****.**', recipients=[form.email.data]) msg.body = "Hello, %s\nThank you for your interest in Griffin Design, we aim to contact you with regards you your request in approximatly 24 hours. Your enquiry was as follows; if that is not correct please contact us.\n\nYour Message: %s\n\nRegards,\nGriffin Design" % ( form.name.data, form.message.data) mail.send( msg ) #Sends the customer an email thanking them for contacting the site return render_template( 'contact.html', success=True ) #re-renders the page with the sucsessflag marked as true so the sucsess box can be displayed elif request.method == 'GET': #if the page was fethced via get it means that the form was not submitted, therefor it just displays the page normally return render_template('contact.html', form=form)
def search_products(): form = ContactForm() if request.method == 'POST': print "==== print:" print form.validate() if form.validate() == False: flash('All fields are required.') return render_template('search.html', form=form) else: msg = Message(form.senderssubject.data, sender='*****@*****.**', recipients=['*****@*****.**']) msg.html = """ <b>From:</b> <i>%s</i> <br> <b>Email-id:</b> <i>%s</i> <br> <b>Message:</b> <i>%s</i>""" \ % (form.sendersname.data, form.sendersemail.data, form.sendersmessage.data) mail.send(msg) form = ContactForm() return render_template('search.html', form=form, success=True) elif request.method =='GET': try: if 'searchKeyword' in request.args: keyword = request.args['searchKeyword'] client = pymongo.MongoClient(MONGODB_URI) db = client.get_default_database() prod_details = db['product_details'] cursor = prod_details.find({'prodCategory': keyword }) # { '$in': [ '/ keyword /' ] } #.sort('prodId', 1) listProd = [] # print ('prodId: %d,Prod Name: %s , Prod Desc: %s.' % (doc['prodId'], doc['ProdName'], doc['ProdDesc'], doc['ProdCount'])) for doc in cursor: print doc['prodName'] #print ('ProdId: %d,Prod Name: %s , Prod Desc: %s, ProdCount: %d' % (doc['ProdId'], doc['ProdName'], doc['ProdDesc'], doc['ProdCount'])) listProd.append(doc) # print str(keyword) # print listProd client.close() return render_template("search.html", form=form, status = "Search Successful!", item2 = listProd, itemlist = listProd, count = max(len(listProd),0)) else: return render_template('search.html', form=form) #, status = "Rendering Page Successfully!", item2 = NULL, itemlist = NULL ) except: e = sys.exc_info()[0] print "exception: " + e
def contact(): form = ContactForm(request.form) if request.method == 'POST' and form.validate(): flash('Thanks for contacting') send_mail(form.subject.data, form.name.data, form.email.data, form.message.data) return redirect(url_for('success')) return render_template('contact.html', form=form)
def submitForm(): # get the form. form = ContactForm() # check if form is valid. if form.validate(): return jsonify(data=form.data) else: return jsonify(data=form.errors), 300
def retailer_dashboard(): form = ContactForm() if request.method == 'GET': return render_template("retailerDashboard.html", form = form) if request.method == 'POST': print "==== print:" print form.validate() if form.validate() == False: flash('All fields are required.') return render_template('retailerDashboard.html', form=form) else: msg = Message(form.senderssubject.data, sender='*****@*****.**', recipients=['*****@*****.**']) msg.html = """ <b>From:</b> <i>%s</i> <br> <b>Email-id:</b> <i>%s</i> <br> <b>Message:</b> <i>%s</i>""" \ % (form.sendersname.data, form.sendersemail.data, form.sendersmessage.data) mail.send(msg) form = ContactForm() return render_template('retailerDashboard.html', form=form, success=True)
def contact(): form = ContactForm() if request.method == 'POST': if form.validate() == False: return render_template('contact.html', form=form) else: return 'Form posted.' elif request.method == 'GET': return render_template('contact.html', form=form)
def contact(): form=ContactForm(request.form) if request.method == "POST" and form.validate() : post_message=Message(form.name.data,form.email.data.lower(),form.message.data) db.session.add(post_message) db.session.commit() mail.send(GetContactMessage(post_message.name,post_message.email,post_message.message)) flash('Your Message has been saved ,Thank you for contacting us.') app.logger.info(post_message.id) return render_template("contact.html",form=form)
def contact(): # create ContactForm instance form = ContactForm() # request determines what type of request comes from browser if request.method == 'POST': if form.validate() == False: flash('All fields are required.') return render_template('contact.html', form=form) elif request.method == 'GET': return render_template('contact.html', form=form)
def contact(): form = ContactForm() if request.method == 'POST': if form.validate() == False: flash("All fields are required!") return render_template('contact.html', form=form) else: sendMessage(form) return render_template('thankyou.html') elif request.method == 'GET': return render_template('contact.html', form=form)
def contact(): form = ContactForm() if request.method == 'POST': if form.validate() == False: flash('All fields are required.') return render_template('contact.html', form=form, action="Add") else: usuario =Usuario(nombre=form.nombre.data,apellido=form.apellido.data ,username=form.username.data, password=form.password.data,perfil=form.perfil.data) # Insert usuario.save() return form.nombre.data + " " +form.apellido.data +" ha sido dado de alta" elif request.method == 'GET': return render_template('contact.html', form=form, action="Alta")
def contact(): form = ContactForm() if request.method == "POST": if form.validate() == False: flash('All fields are required.') return render_template('contact.html', form=form) else: return 'Form posted.' elif request.method == "GET": return render_template('contact.html', form=form)
def contact(): request_config = get_request_config() form = ContactForm() form.category.choices = ((choice, choice) for choice in request_config['categories']) if request.method == 'POST': if form.validate(): send_message(form, request_config) return redirect(request_config['success_url']) return render_template('contact.html', skin=request_config['skin'], form=form)
def contact(): form = ContactForm() if request.method == 'POST': if form.validate() == False: flash('All fields are required.') return render_template('contact.html', form=form) else: return render_template('contact.html', success=True) elif request.method == 'GET': return render_template('contact.html', form=form)
def email(): form = ContactForm(csrf_enabled=False) if request.method == 'POST': if form.validate() == False: #return render_template('contact.html', form=form) print form.errors return "Validation failed", 500 else: #mail.send(msg) ses_result = conn.send_email(app.config['SES_FROM_EMAIL'],form.subject.data,contact_template.render(foo=form.message.data), [form.email.data],format='html') return "Contact API success! AWS response = " + str(ses_result),200
def contact(): form = ContactForm() if request.method == 'POST': if form.validate() == False: flash('All fields are required.') return render_template('contact.html',form=form) else: CreateCollection(db,form.name.data) return form.name.data #return redirect(url_for('home')) elif request.method=='GET': return render_template('contact.html', form=form)
def index(): form = ContactForm() if request.method == 'POST': if form.validate() == False: flash('You must enter something into all of the fields') return render_template('index.html',form=form) else: sub = form.subject.data email = form.email.data message = form.message.data drill(sub,message,email) return render_template('index.html', success=True) elif request.method == 'GET': return render_template('index.html',form=form)
def contact(template): form = ContactForm() if request.method == 'POST': if form.validate() == False: flash('All fields are required.') return render_template('contact.html', form=form, pageName='contact') else: mail.send_mail(sender=CONTACT_SENDER_MAIL, to=adminAccounts(), subject=form.subject.data, body=form.message.data + ' ' + form.name.data + ' , Send by: ' + form.email.data) return render_template('contact.html', success=True, pageName='contact') elif request.method == 'GET': return render_template(template, form=form, pageName='contact')
def contact(): form = ContactForm() if request.method == 'POST': if not form.validate(): return render_template('contact.html', form=form) else: if not form.antispam.data: #We will only email if the bot trap is not checked pool = Pool(processes=1) pool.apply_async(contactFromSendmail, [form]) return render_template('contact_success.html') elif request.method == 'GET': return render_template('contact.html', form=form)
def contact(): from forms import ContactForm form = ContactForm() if request.method == "POST" and form.validate(): from cdw import emailers emailers.send_contact(**form.to_dict()) flash("Thank you for your feedback.") else: print form.errors return render_template("contact.html", section_selector="contact", page_selector="index", form=form)