I use inline registration (6.x-1.x-dev) to have users to register while creating a new node. At the same time, I want the email to be checked twice on the form, thanks to a functionality of login toboggan (6.x-1.6).
So when the 2 modules are activated, I get the following error

warning: array_search() [function.array-search]: Wrong datatype for second argument in /xxx/sites/all/modules/logintoboggan/logintoboggan.module on line 227.
warning: array_unshift() [function.array-unshift]: The first argument should be an array in /xxx/sites/all/modules/logintoboggan/logintoboggan.module on line 231.

Any idea of what might be wrong?

CommentFileSizeAuthor
#13 781066_array_unshift.patch1.06 KBderjochenmeyer

Comments

hunmonk’s picture

Project: LoginToboggan » Inline Registration
Version: 6.x-1.6 » 6.x-1.x-dev

something is clobbering the #submit array prior to the form getting to LT.

i suspect it's the way inline reg. is handling the #submit array in it's form_alter function. it's a bug that inline reg is using array_reverse() to put it's submit handler first -- that completely wrecks the original order of the handlers, which might be important depending on what else is installed. instead, the module should do:

array_unshift($form['#submit'],'inline_registration_submit'); 

that adds the handler to the front of the array without disturbing the other elements.

Lbob’s picture

Hunmonk, thank you for your response.
I'm not a programmer, so I'm afraid I don't understand everything you're saying ;)

However, in inline-registration.module, I replaced $form['#submit'] = array_reverse($form['#submit']); by $form['#submit'] = array_unshift($form['#submit'],'inline_registration_submit'); on line 50.

I still get the same error message... Where did I get it wrong?

hunmonk’s picture

you're using array_unshift() incorrectly. replace your array_reverse() line with the exact line of code i provide in #1.

fyi, it's very easy to search php.net for function help: simply visit php.net/<name_of_function>, like:
http://php.net/array_unshift

Lbob’s picture

I did that too :

   // $form['#submit'] = array_reverse($form['#submit']);
      array_unshift($form['#submit'],'inline_registration_submit');

But I still have the same error...

hunmonk’s picture

what's the exact error message?

Lbob’s picture

same message:

# warning: array_search() [function.array-search]: Wrong datatype for second argument in /sites/all/modules/logintoboggan/logintoboggan.module on line 227.
# warning: array_unshift() [function.array-unshift]: The first argument should be an array in /sites/all/modules/logintoboggan/logintoboggan.module on line 231

hunmonk’s picture

Title: argument error when Inline Registration module is also activated » use array_unshift() instead of array_reverse()

it's not a bug in the code i've given you. something other module is doing nasty things with the $form['#submit'] array, and it shouldn't be.

your issue is out of scope for the bug reported. i suggest you start disabling other contrib modules until the problem goes away, then file another bug with that module.

let's make this issue about fixing the spotted problem with inline reg.

Lbob’s picture

I disabled the following modules, which were the only other modules I was using that had a "$form['#submit']" array in them:
- rules
- hierarchical select
- cck
- location
But that didn't fix the issue: I still get the same error message again...
The only way to get rid of the error message is to disable the 'login tobbogan' module.
Actually, I wouldn't mind disabing it, as long as I find another way to display 2 emails fields in the registration form
=> see http://drupal.org/node/583152

hunmonk’s picture

disable *all* other contrib modules, including inline registration. the only contrib module that should stay enabled for this test is logintoboggan.

if you still have the error after you perform this test, then my only other guess is that there's something seriously broken with your drupal base installation.

boreg’s picture

This happen when login tobogan and inline registration modules are instaled together. I'm also not very skilled programmer, but this error happen when the array is empty, so simple add condition into login tobogan module:

i covered this

$key = array_search('user_register_submit', $form['#submit']);
        if ($key !== FALSE) {
          unset($form['#submit'][$key]);
        }
        array_unshift($form['#submit'],'logintoboggan_user_register_submit');

into this simple condition:

      if ($form['#submit']) {
        $key = array_search('user_register_submit', $form['#submit']);
        if ($key !== FALSE) {
          unset($form['#submit'][$key]);
        }
        array_unshift($form['#submit'],'logintoboggan_user_register_submit');
      }

That works for me well!

Would be great if someone will find better solution. Rather change code in inline registration module, cause its still in development? Anyway looks like its more login tobogan problem, because we always have to assume empty variables :)
Sorry for my english :\

hunmonk’s picture

Anyway looks like its more login tobogan problem, because we always have to assume empty variables :)

no, we shouldn't have to assume that's an empty variable. core should *always* populate that variable, and no module should ever completely unset it.

as a test, enable just core and the logintoboggan module, and see if you get any errors. then enable core, logintoboggan, and inline registration, and see if you get any errors. if you get no errors in the first case, but errors in the second case, then you've triangulated the problem ;)

Rather change code in inline registration module, cause its still in development?

this has nothing to do with anything ;) a bug is a bug, no matter what stage of development a module is in...

Lbob’s picture

Thank you Boreg,

I'll try that, but I had Drupal uninstalled, and now I'm trying other things... I'll keep you posted when I try your solution!

derjochenmeyer’s picture

StatusFileSize
new1.06 KB

Here is a patch that uses array_unshift() in the right position.

In addition to this line, that uses array_reverse

    // And ensure our submit function is called first (so the node is authored by the newly created user)
    $form['#submit'] = array_reverse($form['#submit']);

there's another line that has to be changed, otherwise the 'inline_registration_submit' callback gets added twice:

    // Add our own validation and submit function to the node_form
    $form['#validate'][] = 'inline_registration_validate';
    $form['#submit'][] = 'inline_registration_submit';
elaman’s picture

Issue summary: View changes

Issue is very old. Closing it.

elaman’s picture

Status: Active » Closed (outdated)