Thanks Danny!  I was under the impression that the spam filters only worked
on comments, but I see that i was wrong.

Regards,
Josh


On Tue, Mar 4, 2014 at 3:52 PM, Danny <[email protected]> wrote:

> You can use the SPAM_FILTERS setting to set a list of handlers that
> check form and comment submission for spam.
> The default uses Akismet (if you have it set up in your site
> settings), but you could easily add your own.
>
> For example, I have added the following to my site. I've genericised
> this code a bit:
>
> =================================
> # settings.py
> SPAM_FILTERS = ("mytheme.views.is_spam",)
>
> # mytheme/views.py
> def is_spam(request, form, url):
>     """
>     Validates form data as being 'spam' or not based on a validation
> question.
>     Essentially this should be a field in the form always added that has
> the
>     following properties:
>
>     Label: *must* contain the string "validation code".
>     Type: Single Line Text
>     Required: True
>     Visible: True
>     Default: None
>     Help Text: something useful as to why this question is being asked
>
>     The answer for this example is "foobarqux" but you should change
> it as appropriate
>
>     NOTE: The form submisison goes through regardless, the entry is
> just not saved/emailed if
>     the answer is incorrect.
>     """
>     for name, field in form.fields.items():
>         if field.label and "validation code" in field.label.lower():
>             cleaned_data = form.cleaned_data.get(name)
>             if "foobarqux" in cleaned_data.lower():
>                 # The form field was filled correctly! It's likely not
> spam!
>                 return False
>             else:
>                 # It's spam, not good
>                 return True
>     # else there's no "validation code" field in the form, so we
> accept all submissions
>     return False
>
> =================================
>
> So for the forms that require the validation question, just add a
> field to your form following the comments above, and forms which
> answer incorrectly will be treated as spam.
>
> Unfortunately, this mechanism does not reject the form and tell the
> user they got the question wrong, it just prevents the form submission
> from being emailed.
> If anyone has an easier solution so that form validation can be done
> /prior/ to the submission being accepted, I'd love to see it too.
>
> Seeya. Danny.
>
>
> On 5 March 2014 10:12, Josh Cartmell <[email protected]> wrote:
> > Lately I've had a lot of clients (and a site of my own) getting a lot of
> > spam submitted to Mezzanine forms.
> >
> > I'm wondering if anyone else has encountered this and/or has
> ideas/solutions
> > to cut down on spam submissions.
> >
> > Thanks!
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Mezzanine Users" group.
> > To unsubscribe from this group and stop receiving emails from it, send an
> > email to [email protected].
> > For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
> --
> [email protected]
>
> --
> You received this message because you are subscribed to the Google Groups
> "Mezzanine Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to