diff --git a/README.md b/README.md index ceafae94..73d0989e 100644 --- a/README.md +++ b/README.md @@ -58,11 +58,11 @@ Add this "honeypot" field to avoid spam by fooling scrapers. If a value is provi ### Using AJAX -You can use Formspree via AJAX. This even works cross-origin. The trick is to set the Accept header to application/json. If you're using jQuery this can be done like so: +Formspree Gold users can submit forms via AJAX. This even works cross-origin. The trick is to set the Accept header to application/json. If you're using jQuery this can be done like so: ```javascript $.ajax({ - url: "https://formspree.io/you@email.com", + url: "https://formspree.io/FORM_ID", method: "POST", data: {message: "hello!"}, dataType: "json" diff --git a/formspree/forms/views.py b/formspree/forms/views.py index 34bffa70..fe18bd6c 100644 --- a/formspree/forms/views.py +++ b/formspree/forms/views.py @@ -157,21 +157,21 @@ def send(email_or_string): # or create it if it doesn't exist if not form: - if not url_domain(settings.SERVICE_URL) in host: - form = Form(email, host) - else: + if request_wants_json(): + # Can't create a new ajax form unless from the dashboard + return jsonerror(400, {'error': "Only Gold accounts may create AJAX forms."}) + elif url_domain(settings.SERVICE_URL) in host: # Bad user is trying to submit a form spoofing formspree.io - # Error out silently - if request_wants_json(): - return jsonerror(400, {'error': "Unable to submit form"}) - else: - return render_template( - 'error.html', - title='Unable to submit form', - text='Sorry'), 400 - + g.log.info('User attempting to create new form spoofing SERVICE_URL. Ignoring.') + return render_template( + 'error.html', + title='Unable to submit form', + text='Sorry'), 400 + else: + # all good, create form + form = Form(email, host) - # Check if it has been assigned about using AJAX or not + # Check if it has been assigned using AJAX or not assign_ajax(form, request_wants_json()) if form.disabled: diff --git a/formspree/templates/static_pages/index.html b/formspree/templates/static_pages/index.html index 5fcdbf9d..a44ead72 100644 --- a/formspree/templates/static_pages/index.html +++ b/formspree/templates/static_pages/index.html @@ -81,7 +81,7 @@

4. All set, receive emails

-

Who are you guys?

+

Who are you people?

We're a community of developers that work together to create products. You can contribute on GitHub. {{config.SERVICE_NAME}} is a project that solves a problem many of us have faced: easily adding forms to otherwise static HTML pages.

@@ -204,21 +204,6 @@

_gotcha

-
-
-

Using AJAX

-

You can use {{config.SERVICE_NAME}} via AJAX. This even works cross-origin. The trick is to set the Accept header to application/json. If you're using jQuery this can be done like so: -

- $.ajax({
-     url: "{{config.API_ROOT}}/you@email.com",
-     method: "POST",
-     data: {message: "hello!"},
-     dataType: "json"
- }); -

-
-
-