I upgraded my recaptcha module from 7.x-1.11 to 7.x-2.2.
On one of the pages we were using using AJAX API, and rendering the captcha using the $recaptcha_custom_html = theme('recaptcha_custom_widget');

However this is not supported in 7.x-2.2.How will I need to change my form to support the new recaptcha version?

Below is my captcha form

function whois_lookup_captcha_form(&$form) {
$recaptcha_public_key = variable_get('recaptcha_site_key', FALSE);
// If 'Disable Client-Side Cookies' is set, then add query string to
// end of the public key string before passing to recaptchalib.
if (variable_get('recaptcha_nocookies', FALSE)) {
$recaptcha_public_key .= '&nocookie=1';
}

$recaptcha_options = array(
'theme' => variable_get('recaptcha_theme', 'red'),
'container' => 'recaptcha-ajax-api-container',
'public_key' => $recaptcha_public_key,
);

$recaptcha_custom_html = '';
if ($recaptcha_options['theme'] == 'custom') {
$recaptcha_custom_html = theme('recaptcha_custom_widget');
}

// Localization support.
global $language;
if (isset($language->language)) {
// reCAPTCHA uses two-character language codes, so 'pt-br' must be
// passed as 'pt'; cf. https://developers.google.com/recaptcha/docs/customization#i18n
$recaptcha_options['lang'] = drupal_substr($language->language, 0, 2);
}

$form['captcha_form'] = array(
'#type' => 'item',
// Create the destination container, inserting any custom theme HTML
// necessary ($recaptcha_custom_html will be empty if we are not
// using custom theme).
'#markup' => '

' . $recaptcha_custom_html . '

',
//make sure the recaptcha container is on the bottom for styling purposes
'#weight' => 101,
);

$form['#attached']['js']['https://www.google.com/recaptcha/api/js/recaptcha_ajax.js'] = array(
'type' => 'external',
'scope' => 'footer',
'weight' => JS_LIBRARY,
);

$form['#attached']['js'][] = array(
'data' => array(
'recaptcha' => $recaptcha_options,
),
'type' => 'setting',
);
}

In the JS I am calling function to generate the captcha,

addCaptcha: function () {
var captchatheme = Drupal.settings.recaptcha.theme;
alert(captchatheme);
var settings = {
theme: Drupal.settings.recaptcha.theme,
callback: Recaptcha.focus_response_field,
};

if (typeof Drupal.settings.recaptcha.lang !== 'undefined') {
settings.lang = Drupal.settings.recaptcha.lang;
}

Recaptcha.create(
Drupal.settings.recaptcha.public_key,
this.$captchaContainer.attr('id'),
settings
);
}
};
}(jQuery, Drupal, dust, Recaptcha));

Comments

preetam.chari created an issue. See original summary.

preetam.chari’s picture

Issue summary: View changes
hass’s picture

Status: Active » Fixed

No idea. Remove the broken code and assign recaptcha with captcha module.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.