Show captcha only to users who are not authenticated (open macro failing)

Greg Ennis asked on March 30, 2014 15:44

Hello,

I have a "Contact Us" form for which I need to display a captcha for users who are not logged in, but logged in users should not have to answer the captcha.

I am not using the built-in captcha. I have created a custom form control using Google Recaptcha.

I am using a custom layout for the form. I thought I could simply enclose this inside an open macro like this:

{% if (!CurrentUser.IsAuthenticated()) {%}
 <div class="foo">
  <div class="bar">
   $$input:recpatcha$$
  </div>
 </div>
{% } %}

However, this does not work - it seems to open macros fail if they are enclosing a bizform control. If I take out the $$...$$ then it works.

My question is how to go about implementing this? My other concern is that open macros apparently can not enclose a bizform control - is this a known bug and will it be addressed?

Any suggestions welcome.

Correct Answer

Brenden Kehren answered on March 31, 2014 08:17

Then apply the same macro to those controls. You can set your CSS accordingly if you need. I take this approach all the time. Then there isn't any custom markup in the form itself, just the layout you need. All your code is in the form fields or the CSS.

1 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on March 31, 2014 06:21

Set the visibility macro on the form field itself vs in the html/form.

0 votesVote for this answer Mark as a Correct answer

Greg Ennis answered on March 31, 2014 06:44

Thanks, but that won't work here. I am using a custom form layout. I have other controls for layout surrounding the actual $$ control. I need to hide those too.

0 votesVote for this answer Mark as a Correct answer

Greg Ennis answered on March 31, 2014 09:12 (last edited on December 10, 2019 02:30)

Sorry, I don't quite get it. Are you suggesting I do this?

{% if (!CurrentUser.IsAuthenticated()) {%}
 <div class="foo">
  <div class="bar">
{% } |(identity)GlobalAdministrator%}

This does work, but I'm not happy with it. I'm not sure what you mean by "isn't any custom markup in the form". I am using a custom layout so by definition it is custom markup. Can you explain that?

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on March 31, 2014 09:34

I apologize, I meant custom code in the markup. The approach you have above should work as long as you put the same macro in the field's visibility property. Again not the cleanest but it works.

As I mentioned, I simply use the fields visibility and then handle my CSS accordingly.

0 votesVote for this answer Mark as a Correct answer

Greg Ennis answered on March 31, 2014 10:00

OK thanks.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.