Need to know how to correct this:

Notice: Undefined index: form_id in captcha_after_form_pre_render() (line 95 of /srv/Drupal/7/production/drupal-7.7/sites/all/modules/captcha_after/captcha_after.module).
Notice: Only variable references should be returned by reference in captcha_after_get_captcha_element() (line 171 of /srv/Drupal/7/production/drupal-7.7/sites/all/modules/captcha_after/captcha_after.module).
Notice: Undefined index: form_id in captcha_after_form_after_build() (line 60 of /srv/Drupal/7/production/drupal-7.7/sites/all/modules/captcha_after/captcha_after.module).
Notice: Only variable references should be returned by reference in captcha_after_get_captcha_element() (line 171 of /srv/Drupal/7/production/drupal-7.7/sites/all/modules/captcha_after/captcha_after.module).

Modules Installed:
CAPTCHA 7.x-1.x-dev (2011-May-01)
CAPTCHA After 7.x-1.0

Thanks!...

Comments

x3cion’s picture

Any fix?

carl.brown’s picture

I was getting the 'only variables...' error reported above on a login form block, that I was embedding into a page in my template file.

It seems that updating the following function in captcha_after.module to make sure it returns a variable gets rid of the error. However, I think this is just masking the problem. I don't understand what is going on in the module well enough to really know what I'm doing!

/**
 * Helper function for finding captcha element in form array.
 *
 * @return
 *   Reference to form captcha element.
 */
function &captcha_after_get_captcha_element(&$form) {
  
  // Define variable
  $no_captcha = NULL;

  if (isset($form['captcha'])) {
    return $form['captcha'];
  }

  if (isset($form['actions']['captcha'])) {
    return $form['actions']['captcha'];
  }

  // For node forms.
  if (isset($form['buttons']['captcha'])) {
    return $form['buttons']['captcha'];
  }

  // Return NULL
  return $no_captcha;
}
pivica’s picture

Hi guys,

Tried today to check this bug but I was not able to reproduce it locally. I was testing with D7.8, latest captcha 7.x-1.x-dev (2011-10-12).

Can somebody create exact bug report for this - what is exact configuration that reproduce this bug?

pivica’s picture

Status: Active » Postponed (maintainer needs more info)
R2-D8’s picture

I was getting 'only variables...' error messages on every form where captcha_after is activated.

I found an issue thread from another module where this was also happening:
http://drupal.org/node/1155586

The simple patch from there did it for me.

In captcha_after.module replace...
return NULL;
...with...

$null = NULL;
return $null;
pivica’s picture

Hey R2-D8 thanks, and I fully agree with you about a fix. Problem is that other functions that are calling captcha_after_get_captcha_element() are always expecting to get result and not NULL - so lets say that returning NULL is not a valid at all currently.

Can you tell me for which captcha protected forms you get this error. If you can print_r some $form value from captcha_after_get_captcha_element() call for which you are getting error and send me in attach result from print_r that would be great.

Tezza’s picture

I'm not getting the 'Notice: Undefined index: ...' error message, but I am getting the other error for my Mailing List form:

Notice: Only variable references should be returned by reference in captcha_after_get_captcha_element() (line 171 of [my locahost install]\sites\all\modules\captcha_after\captcha_after.module).

I have Devel module loaded and Display $page array checked. If i drill down through page => what am i looking for that might be of some use to you?

CAPTCHA 7.x-1.0-beta2+4-dev (2012-May-02)
captcha_after 7.x-1.0+1-dev (2012-Feb-29)
mailing_list 7.x-1.0-beta1

pivica’s picture

Hi Tezza and thx for your readiness for helping to solve this bug.

Problem is in function captcha_after_get_captcha_element() which only job is to find captcha element in form array. That function for now checks captcha element in only 3 places in form array. If it fails you will get that 'Notice: Undefined index: ...' error message.

Can you try next. Edit captcha_after.module file and in captcha_after_get_captcha_element() function add next two lines of code

// Debug form array to see where is a 'captcha' element inside of it.
dpm($form);

So your edited function should look like this

function &captcha_after_get_captcha_element(&$form) {
  // Debug form array to see where is a 'captcha' element inside of it.
  dpm($form);
  
  if (isset($form['captcha'])) {
    return $form['captcha'];
  }

  if (isset($form['actions']['captcha'])) {
    return $form['actions']['captcha'];
  }

  // For node forms.
  if (isset($form['buttons']['captcha'])) {
    return $form['buttons']['captcha'];
  }

  return NULL;
}

Now with that change on pages with captcha and activated captcha_after you will see devel debug message which will print $form array. Can you then check that $form array and find where is 'captcha' element inside of it - that is an info we need for this bug.
If you have trouble finding that element just save your page with debug info and attach it here so I can take a look.

Tezza’s picture

StatusFileSize
new130.38 KB

I'm probably being over-cautious but I'm a bit hesitant about posting a page from my site while logged in as user 1. It's likely not an issue so forgive my ignorance, but could I email it to you if the attached jpg is of no value?

pivica’s picture

StatusFileSize
new2.36 KB

jpg image is fine.

Problem is that I do not see captcha element in your form array anywhere - did you check all sub-elements in that array?

Is captcha enabled for that form at all - do you see a captcha widget when you disable captcha_after module?

After that checks and if you still can not figure where possible problem might be can you replace your captcha_after.module with attached file - I've added couple of more debugging statements - when you replace file, just visit your form page, expand debug elements and attach screen-shot so I can take a look.

Tezza’s picture

StatusFileSize
new261.98 KB

Apologies, my screw up. I was bypassing captcha as user 1.

I've now changed permissions and logged in as an administrator on another browser. I don't have a screen capture plugin on Chrome so i've created a PDF of the captcha array.

Hope this is better.

pivica’s picture

Status: Postponed (maintainer needs more info) » Fixed

Nope it is not your mistake, captcha_after should correctly handle that use case - when captcha is skipped. And this was the info I needed to reproduce this bug and fix it. Just pushed fix for this - please test this fix when new dev version is created or just grab latest code from git.

Tezza’s picture

I'm not yet Git-savvy so I'll wait until d.o is updated.

...

Dev of 2012-May-07 fixes my 'Notice: Only variable references...' error. Thanks pivica.

pivica’s picture

Great and thank you Tezza for your help in resolving this bug.

pivica’s picture

Version: 7.x-1.0 » 6.x-1.x-dev
Assigned: Unassigned » pivica
Status: Fixed » Patch (to be ported)

This also need to be ported to 6.x version.

pivica’s picture

Status: Patch (to be ported) » Fixed

Finally ported this to 6.x-1.x.

Status: Fixed » Closed (fixed)

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