def contact(): form = ContactForm(request.form) if request.method == "POST": # There are three differente responses: thanks, invalid, and error response = "thanks" # Use variable_encode to get form entries to a normal dict. dataDict = variable_encode(request.form) responseHeaders = request.headers # We use this checkbox state as an inverse state of spam # If this is checked, we assume a bot ignored the markup and # clicked it. # We then ignore the message, but present a false sense of # success. antispam = True if dataDict.has_key("antispam") else False # If "AJAX" variable was passed via POST, this was an ajax request. isAjax = "AJAX" in dataDict.keys() # Get all invalid field entries. invalid = validation.invalid_fields(dataDict) # If we have any invalid entries at on, we respond with an invalid # indicator. Otherwise, attempt to send the email. if invalid: response = "invalid" elif antispam: response == 'thanks' else: response = send_email(dataDict, responseHeaders) # Just return the response if this is AJAX: Do something with the response # with JavaScript instead of rendering the template. if isAjax: return response else: # Get information based on the response. info = render_template("%s.html"%response, invalid=invalid, page_title="Contact Us") # If the response was thanks, clear the form. if response == 'thanks' : form = ContactForm() return render_template("contact_t.html", form=form, info=info, page_title="Contact Us") else: return render_template("contact_t.html", form=form, page_title="Contact Us")
def contact(): form = ContactForm(request.form) if request.method == "POST": # There are three differente responses: thanks, invalid, and error response = "thanks" # Use variable_encode to get form entries to a normal dict. dataDict = variable_encode(request.form) # If "AJAX" variable was passed via POST, this was an ajax request. isAjax = "AJAX" in dataDict.keys() # Get all invalid field entries. invalid = validation.invalid_fields(dataDict) # If we have any invalid entries at on, we respond with an invalid # indicator. Otherwise, attempt to send the email. if invalid: response = "invalid" else: response = send_email(dataDict) # Just return the response if this is AJAX: Do something with the response # with JavaScript instead of rendering the template. if isAjax: return response else: # Get information based on the response. info = render_template("form_response/%s.html" % response, invalid=invalid) # If the response was thanks, clear the form. if response == 'thanks': form = ContactForm() return render_template("contact.html", form=form, info=info) else: return render_template("contact.html", form=form, title="Contact Us")
def contact(): form = ContactForm(request.form) if request.method == "POST": # There are three differente responses: thanks, invalid, and error response = "thanks" # Use variable_encode to get form entries to a normal dict. dataDict = variable_encode(request.form) # If "AJAX" variable was passed via POST, this was an ajax request. isAjax = "AJAX" in dataDict.keys() # Get all invalid field entries. invalid = validation.invalid_fields(dataDict) # If we have any invalid entries at on, we respond with an invalid # indicator. Otherwise, attempt to send the email. if invalid: response = "invalid" else: response = send_email(dataDict) # Just return the response if this is AJAX: Do something with the response # with JavaScript instead of rendering the template. if isAjax: return response else: # Get information based on the response. info = render_template("form_response/%s.html"%response, invalid=invalid) # If the response was thanks, clear the form. if response == 'thanks': form = ContactForm() return render_template("contact.html", form=form, info=info) else: return render_template("contact.html", form=form, title="Contact Us")