Last updated 9 December 2016. Created on 19 August 2011.
Edited by jrockowitz, DamienMcKenna, sfbob, L. McGurdy. Log in to edit this page.

Drupal 6

  1. Go to Administer > User Management > CAPTCHA and check: Add CAPTCHA administration links to forms.
  2. Create the Webform. Do not click on the CAPTCHA link at the bottom of the Form Create page.
  3. Save the form.
  4. Click CAPTCHA: no challenge enabled at the bottom of the newly created form (when Viewing, not editing the form).
  5. Click Place a challenge here for untrusted users.
  6. Done.

Drupal 7

  1. Go to /admin/config/people/captcha
  2. In the FORM PROTECTION area
    in the configuration table
    go to the last row (with the empty FORM_ID entry field)
  3. Enter the information for this form

    In the FORM_ID column enter the form_id

    To quickly find the form_id of the webform
    take the node id and append it to "webform_client_form_"
    for example if the node id is 3 your webform form_id will be "webform_client_form_3".
    You can also use firebug to inspect the form_id field.

    In the CHALLENGE TYPE column make a selection from the dropdown box
  4. Scroll to the bottom of the page and click the "Save Configuration" button

If you want to programatically add captcha protection to all webforms you have to write a module which implements hook_entity_insert, hook_entity_update and hook_entity_delete.

Method 1

 * Implements hook_entity_insert().
function MYMODULE_entity_insert($entity, $type) {
  _MYMODULE__set_webform_captcha('default', $entity, $type);
 * Implements hook_entity_update();
function MYMODULE_entity_update($entity, $type) {
  _MYMODULE__set_webform_captcha('default', $entity, $type);
 * Implements hook_entity_delete().
function MYMODULE_entity_delete($entity, $type) {
  _MYMODULE__set_webform_captcha(NULL, $entity, $type);
 * Helper function to set (or unset) a captcha whenever any webform is changed.
function _MYMODULE__set_webform_captcha($captcha_type, $entity, $entity_type) {
  if (module_exists('webform') && module_exists('captcha') && !empty($entity->webform)) {
    list($webform_id) = entity_extract_ids($entity_type, $entity);
    module_load_include('inc', 'captcha');
    $form_id = 'webform_client_form_' . $webform_id;
    captcha_set_form_id_setting($form_id, $captcha_type);

Method 2 (confirmed that this works)

In template.php add the following

function MYTHEME_form_alter( &$form, &$form_state, $form_id ){
	if (strstr($form_id, 'webform_client_form')) {
			$form['my_captcha_element'] = array(
				'#type' => 'captcha',
				'#captcha_type' => 'Math',

Two things to note.

1) MYTHEME_form_alter must be changed to the name of your theme. Don't just copy and paste :)

2) captcha_type can be set to the following:

'default', 'none', 'captcha/Math', 'image_captcha/Image'

Original solution here:

Method 3

Another approach is to enable the CAPTCHA via the CTools API by adding this to a custom module:

 * Implementation of hook_captcha_default_points_alter().
 * Enable CAPTCHA integration for all Webforms.
function MYMODULE_captcha_default_points_alter(&$items) {
  // Only proceed if the Webform module is enabled.
  if (module_exists('webform')) {
    // Get the list of supported Webform content types.
    $webform_types = webform_node_types();
    if (!empty($webform_types)) {
      // Get a list of all nid's for all supported webform content types.
      $webforms = array();
      $nodes = db_select('node')
        ->fields('node', array('nid'))
        ->condition('type', $webform_types)
      foreach ($nodes as $node) {
        // Webform form IDs follow this format.
        $webforms[] = 'webform_client_form_' . $node->nid;

      // Enable CAPTCHA integration for each form, if it isn't already enabled.
      foreach ($webforms as $form_id) {
        if (!isset($items[$form_id])) {
          $captcha = new stdClass;
          $captcha->disabled = FALSE;
          $captcha->api_version = 1;
          $captcha->form_id = $form_id;
          $captcha->module = '';
          // This may be 'node', 'default', 'captcha/Math',
          // 'recaptcha/reCAPTCHA', etc.
          $captcha->captcha_type = 'default';
          $items[$form_id] = $captcha;

Looking for support? Visit the forums, or join #drupal-support in IRC.


Vojta’s picture

Is it possible to protect by CAPTCHA all webforms? By this I can add CAPTCHA only for one page, right?

Marco Piccolino’s picture

Are instructions at the top for Drupal 6? If so please make it clear.


VVS’s picture

How programmatically add webform to "Form Protection"? Not for all webforms (as hook).

erbeck’s picture

I'm having trouble with this for some reason. Trying to implement the instructions for Drupal 7. I'm working on the following webform: I add the following Form ID to the list in CAPTCHA settings: webform_client_form_108, and I choose the challenge type of "image." No change to the webform. I clear the CAPTCHA cache, not a thing. I don't think there's anything unusual with the way the webform is configured. I'm using CAPTCHA 7.x-1.1 and Webform 7.x-3.20, which to my knowledge are both up-to-date. Anybody have any advice about this?

gumdal’s picture

I am stuck exactly at the same point. @erbeck - Were you able to fix this problem? I saw in your website and could not find Captcha integrated in the website, did you find any success with it?

Raj Pawan G

gumdal’s picture

Rightfully so, the captcha is not displayed when user is logged into the website. If you open the webform in incognito mode or after you logout it starts showing the captcha module.

Raj Pawan G

tregismoreira’s picture

Hey guys. I created a simple module that implements this code: Maybe it will be more user friendly than coding a new module.

arnoldbird’s picture

I don't know how to use the module. Please see

jaesperanza’s picture

Clarifying that Webform for D7 has this option already if you have Captcha and reCaptcha modules installed.

Just edit your webform node > under Webform tab > CAPTCHA: CHALLENGE "RECAPTCHA" ENABLED > set to Enable.

subadmin’s picture

Is there a way to save captcha in webform result as all the submission save and shown in website submission result. ?

Tronux’s picture

Note, you need to edit a settings in the Captcha module namely: Add CAPTCHA administration links to forms.
Then in the webform settings you can enable AND add your captcha.

arnoldbird’s picture

I see this setting, but it does not work. This does not place a captcha in a webform.

Miri Meltzer’s picture

// Set captcha image for specific webform form.
module_load_include('inc', 'captcha');
$form_id = 'webform_client_form_' . $my_form_id();
$captcha_type = 'image_captcha/Image';
captcha_set_form_id_setting($form_id, $captcha_type);

Todd Zebert’s picture

For setting $captcha_type at least in Captcha 7.x-1.x, the format is module/type, ex: 'recaptcha/reCAPTCHA'.

IT Sherpa, Drupal and full-stack developer, Consulting CTO. Loves JavaScript.
Organizer for Drupal LA Meetup and Camp