Hi there,

The module is working great, but I am having a problem concerning the registration of new users through the services api (Service module)... So far if I have the captcha enabled, when I send the api request to register it asks to enter the captcha code. Everything work fine with captcha disabled.

I was wondering if anybody would know how to avoid to check the captcha if the submission contains an extra parameter like 'captcha=no' for example ?

I managed to get :

function krem_form_alter(&$form, &$form_state, $form_id){
  if($form_id = "user_register_form"){
  	//drupal_set_message("Form ID iseeeeeee : " . $form_id);
  	captcha_set_form_id_setting('user_register_form', 'none');
  }
}

But this way it changes the form itself, I need to disable the captcha within the submit function, after the form is submitted.

Any clue ?

Comments

soxofaan’s picture

You could remove the CAPTCHA element with unset($fom['path']['to']['captcha']);. You have to know the right "path" to the captcha element, but it will not be a difficult one for the register form. Also note that this only works if your krem module comes after the captcha module.

BTW: I hope you plan to use a more difficult/secret parameter than 'captcha=no'.

krem’s picture

Thanks, I found another way to do it, but I prefer yourswhich is more logical :

function krem_form_alter(&$form, &$form_state, &$form_id){
  if($form_id = "user_register_form"){
      if(!arg(2)){
	  	$form['captcha'] = array(
		  '#type' => 'captcha',
		  '#captcha_type' => 'image_captcha/Image',
		);
    }
  }
}

Of course the condition won't be as simple, it is just for demo purpose ;)

soxofaan’s picture

Status: Active » Fixed

no problem

Status: Fixed » Closed (fixed)

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

doctorDrupal’s picture

Status: Closed (fixed) » Active

Hi!

How did you get this to work? I'm currently using Drupal iOS SDK which allows my iPhone app to communicate with Drupal via the Services module. Whenever I disable the registration page CAPTCHA, I'm able to successfully create a new account from within the app. I would like to keep CAPTCHA enabled for the registration form except for when a web service accesses it. How did you get around this with your custom module? I'm open to going that route but I'm not exactly sure how to send arg2 and what those values should be. Additionally, I'm not sure what the correct path for the registration form is.

Any assistance would be appreciated. Thanks in advance for your help!!!!

mcrittenden’s picture

Status: Active » Closed (fixed)

This worked for me:

function MODULENAME_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'user_register_form') {
    if (arg(0) == 'api') { // You might have to update this line depending on the path to your API
      unset($form['captcha']);
    }
  }
}
doctorDrupal’s picture

Sweet--thanks, mcrittenden!

A couple of questions:

1. Is the code you posted added to the MODULENAME.module file or to a pre-existing Drupal file?

2. If the endpoint for my Drupal service is json and the path to the user service is user, would I put 'json/user' where you have 'api'?

To be honest, I'm not exactly sure what the exact path to the user registration service that Drupal iOS SDK uses is. I'm particularly confused because my kDiosBaseUrl is http://mysite.com, kDiosEndpoint is json, and kDiosBaseUser is user. As such, shouldn't the path in "NSString *path = [NSString stringWithFormat:@"%@/%@/register", kDiosEndpoint, kDiosBaseUser];" be mysite.com/json/user/register? When I put that path in my browser window, I get a "This link appears to be broken" error. Of note, the user register service is enabled and functioning properly.

Thanks for your help again!!!!!

mcrittenden’s picture

1. Is the code you posted added to the MODULENAME.module file or to a pre-existing Drupal file?

It's added to a MODULENAME.module file.

2. If the endpoint for my Drupal service is json and the path to the user service is user, would I put 'json/user' where you have 'api'?

Not exactly. arg(0) returns the first part of the current URL. So if the URL you're hitting is json/user/register, then arg(0) will be "json" in which case you'll need to change the "api" in my code to "json".

Not sure I can help with your iOS issues. Sounds like that's unrelated to CAPTCHA and your API isn't working at all for some reason, in which case you should probably follow up in the issue queue for whatever module you're using for the iOS SDK.

doctorDrupal’s picture

This worked beautifully and exactly as I wanted it to. Thank you, mcrittenden!

d3vo’s picture

Works perfect! Thanks mcrittenden!

shane birley’s picture

Issue summary: View changes

Perhaps we should turn this into a project. I am seeing this more and more with CAPTCHA, Honeypot, or other anti-spam measures. A field in the Services module with the ability to add a path specifically to remove any CAPTCHAs, etc.

hodba’s picture

#6 worked perfectly for me.