Google reCAPTCHA for ProcessWire. This module simply adds reCAPTCHA to your form.
site/modules
zip file
, extract it in your sites/modules
directoryYou must create an API key prior to use this module. Goto https://www.google.com/recaptcha/admin to create your own. Next, add the API keys information to the module's settings.
$captcha = $modules->get("MarkupGoogleRecaptcha");
$captcha->getScript();
somewhere to get the javascript used by reCAPTCHA<form></form>
by calling $captcha->render()
or
Render reCAPTCHA in an InputfieldForm
by passing as argument your form to the render function: $captcha->render($form)
verifyResponse()
to get the result. It return TRUE
if the challenge was successfull.$out = '';
$captcha = $modules->get("MarkupGoogleRecaptcha");
// if submitted, check response
if ($captcha->verifyResponse() === true)
{
$out .= "Hi " . $input->post["name"] . ", thanks for submitting the form!";
}
else
{
$form = $modules->get("InputfieldForm");
$form->action = $page->url;
$form->method = "post";
$form->attr("id+name", "form");
$field = $this->modules->get('InputfieldText');
$field->name = "name";
$field->placeholder = "name";
$form->add($field);
// CAPTCHA - our form as argument, the function will add an InputfieldMarkup to our form
$captcha->render($form);
// add a submit button
$submit = $this->modules->get("InputfieldSubmit");
$submit->name = "submit";
$submit->value = 'Submit';
$form->add($submit);
$out .= $form->render();
$out .= $captcha->getScript();
}
echo $out;
$captcha = $modules->get("MarkupGoogleRecaptcha");
// if submitted check response
if ($captcha->verifyResponse() === true)
{
$out .= "Hi " . $input->post["name"] . ", thanks for submitting the form!";
}
else
{
$out .= "<form method='post' action='{$page->url}'>\n"
. "\t<input type='text' name='name'>\n"
. $captcha->render() // render reCaptcha
. "\t<input type='submit'>\n"
. "</form>\n";
$out .= $captcha->getScript();
}
echo $out;