Recaptcha for Reason Forms

10 views
Skip to first unread message

Amanda

unread,
Mar 22, 2012, 11:04:20 AM3/22/12
to Reason Discussion
We are trying to add a form view that allows forms to include
Recaptcha and are having issues getting it to work properly. I am
wondering if anyone else has tried to add Recaptcha to forms and been
successful? The approach we are trying to use is to have a form view
that includes the Recaptcha code for checking if the user's submitted
response is correct in the run_error_checks() function. In that same
form view, by referencing the setup for the polling module display,
the on_every_time() function is calling a new form class that is
modeled after the boxes.php form class and includes the code for
displaying the Recaptcha on the form.

We are able to get the Recaptcha to work, but are coming across
various issues for different circumstances. For example:

If the Recaptcha is submitted incorrectly, and you go back to the form
to resubmit it, the Submit button is disabled in Firefox.

I was also initially coming across the problem of if the Recaptcha is
submitted correctly, but there are errors on the form itself, after
the user fixed the errors (i.e. Filled in required fields that were
left blank) and resubmitted the form, it redirected back to a blank
form with the Recaptcha and would not submit correctly. I tried to
remedy this issue by creating a variable is set in the
run_error_checks() function that would not display the Recaptcha again
if it had been submitted correctly, and then ran in to the problem of
having it still checking the Recaptcha and saying it was entered
incorrectly even though there was no Recaptcha on the page to submit
because it had already been submitted correctly. (I tried to have it
not call the Recaptcha checking code similarly to having it not
display the Recaptcha to begin with, but I am thinking that the
functions in the form view run each time the form is submitted and
therefore it isn't recognizing the variable I am trying to set in
there.)

I don't know if there is another function I might be able to use in
the form view to get it to work or some other strategy I should be
using. Any feedback would be greatly appreciated.

Thanks,
Amanda

Matt Ryan

unread,
Mar 22, 2012, 1:57:06 PM3/22/12
to reason-d...@googlegroups.com
I have not tried to integrate recaptcha with Reason forms.

However, I would start by creating a recaptcha plasmature element
rather than using the box class. The box class is really ill-defined
for this sort of thing, and doesn't have good ways to access data.

Plasmature elements, however, have built-in error checking -- so the
element could (theoretically) just check whether the supplied answer
is correct and set a Disco error if it is not. Then a new form would
be displayed to the user (with a new recaptcha).

If things are done this way I don't think there should be any problems
with the submit button. It's possible that the other problem you are
seeing would be easier to resolve with plasmature too.

But these are just preliminary thoughts. Feel free to ask for help
with creating a plasmature element (all the native Disco ones are in
disco/plasmature/; there are also Reason-specific ones in
reason_4.0/lib/core/classes/plasmature/ .

Matt

> --
> You received this message because you are subscribed to the Google Groups "Reason Discussion" group.
> To post to this group, send email to reason-d...@googlegroups.com.
> To unsubscribe from this group, send email to reason-discuss...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/reason-discussion?hl=en.
>

Amanda

unread,
Mar 23, 2012, 12:55:31 PM3/23/12
to Reason Discussion
Ok, please let me know if I am understanding correctly:

1. In the plasmature element, I can put in the code to display the
recaptcha on the form (in the get_display() or display() function?) as
well as the code that checks the recaptcha (in the run_error_checks()
function) ? Not having ever created a plasmature element, and having
looked at those that are out there, I think I have an idea of what to
do, but any further direction you might have would be great as well.

2. I think where I get the most lost is how to up the form view to the
plasmature element in order to have the recaptcha applied to the form.

Thanks,
Amanda

Matt Ryan

unread,
Mar 23, 2012, 3:07:31 PM3/23/12
to reason-d...@googlegroups.com
It sounds like you're on the right track regarding setting up the
plasmature element.

To add the element to Disco, make sure you've included the file that
contains the new plasmature element, then in in your form view, add it
to on_every_time(), e.g:

function on_every_time()
{
$this->add_element('are_you_human','recaptcha');
}

The 1st parameter is the name of the element in this disco form --
it's the handle you can use later when you want to reference it.

The 2nd parameter is the plasmature type you want to use. In this
example I'm assuming you named your plasmature element class
"recaptchaType"; plasmature element types are referred to in Disco by
the name of the class minus the "Type" on the end.

You can then treat it like any other element of the form -- move it
around, etc. by referring to the element's name.

Matt

Reply all
Reply to author
Forward
0 new messages