1

I wanted to add reCaptcha to the comment form, but only for non-authenticated users.

I've created my own comments app, using reCaptcha more or less according to this post, except that I don't have any (explicit) view function to post the comment, but instead I check captcha as a part of form validation process. Everything works fine so far.

Now, how do I disable reCaptcha for a logged in user? Removing all reCaptcha-related fields in the template is no problem, but how do I validate the form, not checking captcha if the comment if from an authenticated user? Alternatively, is there a way to use two different comment form classes, depending on whether the user is authenticated or not?

UPDATE: I sort of solved the problem by creating a view for processing POST request for comments, where I validate the captcha first and then call the default view; I also had to add an entry for it into the urls.py. But was it really wrong to try and validate captcha in the form class?

Headcrab
  • 6,838
  • 8
  • 40
  • 45
  • the edit_form (in the post) does not have any re-captch field. The recaptcha is present in template and views. Whats the problem in editing the view to not "talk to the captcha service" if user is authenticated? – Konstant Oct 27 '12 at 11:32
  • What "view" are you referring to? I have {% get_comment_form for entry as form %} in the template file, and then a bunch of fields like {{form.name}}, {{form.email}}, {{form.comment}} and so on in the same template. Then I have a form class like this: RecaptchaCommentForm(CommentForm): ... in the comments app's forms.py. It validates the captcha and calls the super-class' method to do the rest of the validation. That's all. Which view shall I edit how? – Headcrab Oct 27 '12 at 12:25

0 Answers0