Jump to content

Markup Google reCAPTCHA

Recommended Posts

  • 1 month later...
  • 4 months later...
On 9/30/2018 at 7:29 PM, Jonathan Lahijani said:

Does this work with FormBuilder?

That's a good question!  When I developed this module I didn't had FormBuilder in hand.

Now that I have a copy of this module, I will try to see if it works out of the box tomorrow. Stay tuned !

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

  • 3 months later...

@gregory @Jonathan Lahijani


I tested it (but not with all the Custom Embed option), it works with the Custom Embed options C and D.


Use the following hook :

<?php namespace ProcessWire;
// the captcha module
$captcha = $this->modules->get("MarkupGoogleRecaptcha");
// hook FormBuilder
$forms->addHookBefore('FormBuilderProcessor::renderReady', function ($e) use ($captcha) 
    $form = $e->arguments(0);
    // do some custom check here ...
    if ($captcha->data_recaptcha_type === 'invisible') { // invisible captcha
        $f = $this->modules->get("InputfieldHidden");
        $f->attr('id+name', 'login_submit');
        $f->value = 'login_submit';
    } else { // recaptcha v2
        $f = $this->modules->get("InputfieldMarkup");
        $f->value = $captcha->render();
        foreach ($form->children as $field) {
            if ($field instanceof InputfieldSubmit) { // find the submit button
                $form->insertBefore($f, $field);      // insert reCAPTCHA before the submit button



I will test later to see if it's possible to embed the captcha into an IFrame.


  • Like 2
Link to comment
Share on other sites

  • 2 weeks later...
  • 2 months later...

Great Module, thanks.

I had some luck getting this to integrate with FormBuilder (method d) by using the following Form Builder hook to check the recaptcha before submitting:

$forms->addHookBefore('FormBuilderProcessor::processInputDone', function ($e) use ($captcha) {
$form = $e->arguments(0); // retrieve argument by number (zero based)
    // Check to see if recaptcha is true
	if ($captcha->verifyResponse() === true) {
        // This will process the form as usual
	} else { 
        // This will cause an error on form and stop processing 
        $form->error('Recaptcha is missing. Please tick I\'m not a robot and try again');

More info on FormBuilder hooks: https://processwire.com/blog/posts/formbuilder-v34/


  • Like 1
Link to comment
Share on other sites

  • 2 months later...
On 7/9/2016 at 11:45 AM, flydev said:

$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;

Hello, can anyone sho thw right example ? The one with plain HTML doesnt work. 

And i really dont understand why ??  

Parse Error: syntax error, unexpected '}' (line 26 of /usr/www/xxxxx/site/templates/contact.php) 



Link to comment
Share on other sites

hi @iNoize

Looking at the error and the corresponding line (26) pointing to an empty line, I bet that you have some unwanted char in the code caused by the copy/pasta from the forum.

Try to open your file (contact.php) with another editor and clean weird chars. The plain HTML code should work as is.

Please have a read to those post :






If you still have an issue, ping me, I will check your templates.

Edited by flydev
Related Links
Link to comment
Share on other sites

I use the module regularly on sites (with Pw form API), but for the first time I needed to implement the module in a plain HTML form, but without any luck.

render() will not render anything and the getScript() does not add the script at the bottom of my form.

Does plain HTML still work?


Link to comment
Share on other sites

1 hour ago, flydev said:

Hi @KarlvonKarton  thanks for reporting it.

Can you tell me on which version of ProcessWire the module didn't work for you ? 

I did the same mistake as someone here above...  I did not echo the render() nor the getScript() ... (my form is in plain HTML and not in a var called $out, therefrom...)
It's working now. ;-)

  • Thanks 1
Link to comment
Share on other sites

  • 2 months later...

@flydev Great module.

It would be nice to have/force a different language or multi-language support. Right now Google renders the widget in what it thinks is you native language. For me that's Dutch, although the html lang="en", the site's default language and my browser is in English as well.

This could be done via a simple extra parameter in your module's getScript() and a "hl=langcode" setting, ie.:
<script src='https://www.google.com/recaptcha/api.js?hl=en'></script>
There's a list at https://developers.google.com/recaptcha/docs/language

Edit 1: Already figured out you can do this via the ->render("","en") method.
Edit 2: Somehow that's not working. But I expect it's Google's fault. It renders "en" but still displays it in Dutch.


Edit 3: It was Google's fault. When you're logged in with your Google account in Chrome (aka 'sync') it will take the language of that account, no matter what language you asked the widget to be. Google always knows better™ 🙄

Edited by JFn
  • Thanks 1
Link to comment
Share on other sites

  • 1 month later...
  • 5 months later...

Dear All and @flydev 👊🏻

i am currently creating a contact form and wanted to use the Google recaptcha for this.

While implementing, I come across the following problem that I can not get solved...

My page code structure looks something like this:

<?php namespace ProcessWire; ?>

<div id='content-body'>

	<div class='uk-grid' data-uk-grid>
		<div id='content' class='uk-width-1-2@m'>

		<div id='contactform' class='uk-width-1-2@m'>
			<h3>Contact Form</h3>

			<?php // Google reCaptcha as Modul
			$captcha = $modules->get("MarkupGoogleRecaptcha");


			// form was submitted so we process the form
			if($input->post->submit) {
				// Do cool stuff here  			 <<<<-------- I cannot get in here

			<form class="uk-form-stacked" action="./" method="post">
			<div class="uk-margin">
				<label class="uk-form-label" for="name">Your Name <span class='uk-text-danger'>*</span></label>
				<div class="uk-form-controls">
					<input type="text" name="name" class="uk-input" value="<?php echo $name?>" placeholder="Your Name here">
			<div class="uk-margin">
				<label class="uk-form-label" for="email">Your Email-Adress <span class='uk-text-danger'>*</span></label>
				<div class="uk-form-controls">
					<input type="email" name="email" class="uk-input" value="<?php echo $email?>" placeholder="Email-Adress">
				<!-- Google reCaptcha code START -->
				<?php echo $captcha->render()?>
				<!-- Google reCaptcha code END -->
			<div class="uk-margin">
				<input type="submit" name="submit" class="uk-button uk-button-default" value="Submit">

		<?php echo $captcha->getScript(); ?>


My problem is now, as soon as I insert this line of code "<?php echo $captcha->getScript(); ?>" on the page like this, my query "if($input->post->submit)" does NOT work anymore ....

HELP what is wrong here or where is my mistake?


Link to comment
Share on other sites

Hi @Ralf, sorry for the delay.

Instead of checking for the $input->post->submit, you should check if the response from the ReCaptcha is green.

So, instead of :

// form was submitted so we process the form
if($input->post->submit) {
   // Do cool stuff here  			 <<<<-------- I cannot get in here

Do :

// form was submitted so we process the form
if($captcha->verifyResponse() === true) {
   // Do cool stuff here  			 <<<<-------- you will get here now


Also, try to call the getScript() method on the end of your main markup page. I mean, just before the </body></html> tags. And to avoid calling the module every page request, you can for exemple, check if the current page's template is the contact one and then call the module's getScript() method :


   <!-- other tiers scripts exemple -->
   <script src="jquery.js"></script>
   <script src="anotherscript.js"></script>
   if($page->template->name === 'contact-tpl') {
     // google recaptcha required script
     echo $modules->get("MarkupGoogleRecaptcha")->getScript();



Ping me if you need further help.

  • Like 2
Link to comment
Share on other sites

  • 1 year later...

reCaptcha v2 invisible doesn't seem to be working (or what am I to expect? I've never seen an example for the invisible version anyway – kind of ironic, I know).

I had reCaptcha v2 (the regular one) working just fine.

Now that I want to change it to invisible I…

  • added a new site-project in the reCaptcha-settings on google.com
  • selected "invisible" in this module's settings
  • and entered the newly created site key and secret key in this module's settings as well as in the div-attribute on the template.

refreshed the page (cleared cookies and cache just to be save) but I see no change whatsoever.


Link to comment
Share on other sites

  • 3 weeks later...

Hi @flydev 👊🏻 I just installed the module and I'm getting this PHP Notice:

Notice: Undefined index: data_badge in C:\laragon\www\mysite\site\assets\cache\FileCompiler\site\modules\MarkupGoogleRecaptcha\MarkupGoogleRecaptcha.module on line 269

Replacing the 269 line with this, fixes the issue:

if(isset($data['data_badge'])) $f->attr('value', $data['data_badge']);


  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By kixe
      Field that stores one or more references to ProcessWire pages with additional data in field context.
      Values are editable via page edit modal of the referenced page provided from the field if module AdminPageFieldEditLinks is installed and "Enable link to create new pages?" is checked in field settings.
      Requirements: AdminPageFieldEditLinks >= 3.1.4
      Use case example:
      The planning of the Tonmeistertagung in the CCD (Congress Center Düsseldorf) from November 3rd, 2021 to November 6th, 2021 is in the finalization phase.
      The conference consists of a conference part and an exhibition. The planning is done via a separate frontendless PW instance. There, all companies (pages) that are active at various events are kept in a pool. Changes (address, logo) can always be done there. For the exhibition of the current conference in November, the exhibitor-companies (pages) are selected via a page reference field. A stand number must now be assigned to each selected company (page). We had originally solved this using the Profield FieldtypeTable. However, this had the disadvantage that each entry again made all companies available for selection and did not recognize which were already selected in a previous table row. The new field type now allows the value (company's stand number) to be assigned to a Company (page) in context to a specific Pagefield living in a specific page.
    • By Robin S
      This module lets you add some custom menu items to the main admin menu, and you can set the dropdown links dynamically in a hook if needed.
      Sidenote: the module config uses some repeatable/sortable rows for the child link settings, similar to the ProFields Table interface. The data gets saved as JSON in a hidden textarea field. Might be interesting to other module developers?
      Custom Admin Menus
      Adds up to three custom menu items with optional dropdowns to the main admin menu.
      The menu items can link to admin pages, front-end pages, or pages on external websites.
      The links can be set to open in a new browser tab, and child links in the dropdown can be given an icon.
      Requires ProcessWire v3.0.178 or newer.
      Example of menu items

      Module config for the menus

      Link list shown when parent menu item is not given a URL

      Setting child menu items dynamically
      If needed you can set the child menu items dynamically using a hook.
      $wire->addHookAfter('CustomAdminMenus::getMenuChildren', function(HookEvent $event) { // The menu number is the first argument $menu_number = $event->arguments(0); if($menu_number === 1) { $colours = $event->wire()->pages->findRaw('template=colour', ['title', 'url', 'page_icon']); $children = []; foreach($colours as $colour) { // Each child item should be an array with the following keys $children[] = [ 'icon' => $colour['page_icon'], 'label' => $colour['title'], 'url' => $colour['url'], 'newtab' => false, ]; } $event->return = $children; } }); Create multiple levels of flyout menus
      It's also possible to create multiple levels of flyout submenus using a hook.

      For each level a submenu can be defined in a "children" item. Example:
      $wire->addHookAfter('CustomAdminMenus::getMenuChildren', function(HookEvent $event) { // The menu number is the first argument $menu_number = $event->arguments(0); if($menu_number === 1) { $children = [ [ 'icon' => 'adjust', 'label' => 'One', 'url' => '/one/', 'newtab' => false, ], [ 'icon' => 'anchor', 'label' => 'Two', 'url' => '/two/', 'newtab' => false, 'children' => [ [ 'icon' => 'child', 'label' => 'Red', 'url' => '/red/', 'newtab' => false, ], [ 'icon' => 'bullhorn', 'label' => 'Green', 'url' => '/green/', 'newtab' => false, 'children' => [ [ 'icon' => 'wifi', 'label' => 'Small', 'url' => '/small/', 'newtab' => true, ], [ 'icon' => 'codepen', 'label' => 'Medium', 'url' => '/medium/', 'newtab' => false, ], [ 'icon' => 'cogs', 'label' => 'Large', 'url' => '/large/', 'newtab' => false, ], ] ], [ 'icon' => 'futbol-o', 'label' => 'Blue', 'url' => '/blue/', 'newtab' => true, ], ] ], [ 'icon' => 'hand-o-left', 'label' => 'Three', 'url' => '/three/', 'newtab' => false, ], ]; $event->return = $children; } }); Showing/hiding menus according to user role
      You can determine which menu items can be seen by a role by checking the user's role in the hook.
      For example, if a user has or lacks a role you could include different child menu items in the hook return value. Or if you want to conditionally hide a custom menu altogether you can set the return value to false. Example:
      $wire->addHookAfter('CustomAdminMenus::getMenuChildren', function(HookEvent $event) { // The menu number is the first argument $menu_number = $event->arguments(0); $user = $event->wire()->user; // For custom menu number 1... if($menu_number === 1) { // ...if user does not have some particular role... if(!$user->hasRole('foo')) { // ...do not show the menu $event->return = false; } } });  
    • By tcnet
      This module for ProcessWire sends a notification email for each failed login attempt. Similar modules exists already in the module directory of ProcessWire. However, this module is designed to notify, even if specified user doesn't exist.
      The settings for this module are located in the menu Modules=>Configure=>LoginFailNotifier.
      Notification email
      Specifies the email address to which the notification emails should be sent.
        Email subject
      Specifies the subject line for the notification email.
        Post variables
      Specifies the $_POST variables to be included in the notification email. Each variable must be separated by a comma. For example: login_name,login_pass
        Server variables
      Specifies the $_SERVER variables to be included in the notification email. Each variable must be separated by a comma. For example: REMOTE_ADDR,HTTP_USER_AGENT
      Link to ProcessWire module directory:
      Link to github.com:
    • By Fokke
      ProcessWire 3.x markup module for rendering meta tags in HTML document head section. Note that this module is not a full-blown SEO solution, but rather a simple tool for rendering meta tags based on module configuration. Adding custom meta tags is also supported.
      Built-in meta tags
      The following meta tags are supported out-of-the-box:
      Document title consisting of page title and site name Character set Canonical Viewport Description Keywords Hreflang tags Open Graph og:title og:site_name og:type og:url og:description og:image og:image:width og:image:height Twitter meta tags twitter:card twitter:site twitter:creator twitter:title twitter:description twitter:image Facebook meta tags fb:app_id The full documentation with configurable options can be found here: https://github.com/Fokke-/MarkupMetadata
      ProcessWire>=3.0.0 PHP >=7.1 Installation using Composer
      composer require fokke/markup-metadata Manual installation
      Download latest version from https://github.com/Fokke-/MarkupMetadata/archive/master.zip Extract module files to site/modules/MarkupMetadata directory.
    • By m.sieber
      ITRK-Service for ProcessWire
      Module for the automated transfer of imprint, data protection declaration and terms and conditions from IT-Recht Kanzlei to your ProcessWire installation
      What is ITRK Service for ProcessWire?
      ITRK-Service for ProcessWire is a free module for ProcessWire CMS. It provides an interface to the update service of IT-Recht Kanzlei, via which the legal texts of your online presence are automatically updated. In this way, the texts remain legally secure and warning-proof in the long term. Imprint, data protection declaration, revocation and general terms and conditions are currently supported.
      You can find our documentation (in german language) here: https://www.pupit.de/itrk-service-for-processwire/dokumentation/

      Download: https://www.pupit.de/itrk-service-for-processwire/
      Github: https://github.com/pupit-de/pwItrkServiceConnector
  • Create New...