I've just been working on a patch to refactor access rules into a separate module and spent about an hour trying to work out why I'd broken admin/user/user/create to cause a WSOD on form submission.

Turns out it's broken in HEAD...

Getting array to string conversion in includes/form.inc on line 670.

Comments

floretan’s picture

The cause of the problem is that _form_validate() gets called before password_confirm_validate(), but this second function is the one where form_set_value() is called to change the structure of form elements of type password_confirm from an array

array(
  [pass1] => 'password',
  [pass2] => 'password',
);

to a string

'password'

In this case we actually want the element-specific validation to be called before the generic validation for required fields, or add a flag to indicate that certain elements handle their own "#required" validation.

With the possibility of having fields in core, there will probably be more composite form elements like this, so a general solution would be a better time investment than making a special case for elements of type password_confirm

catch’s picture

Status: Active » Closed (duplicate)

pwolanin kindly directed me to the original issue for this, which was fixed in 6.x but not committed to HEAD yet: http://drupal.org/node/11774

Sorry for the duplicate (and thanks flobruit - if you have ideas about a more generic solution I'm sure that'd worth pursuing).

nonsie’s picture

Version: 7.x-dev » 6.4
Status: Closed (duplicate) » Active

This is broken in 6.4 resulting in warning: mb_strlen() expects parameter 1 to be string, array given in C:\xampp\htdocs\drupal64\includes\unicode.inc on line 404.

Here's a related thread - http://drupal.org/node/289800

The link in #2 links to a theming overview node - I'd love to find out what the solution to this bug was

catch’s picture

#2 is the wrong link, at the moment I can't find what the correct link ought to be.

gábor hojtsy’s picture

Would be great to find out. Is this still an issue in 6.8?

catch’s picture

Status: Active » Fixed

I don't think so - nonsie's bug has it's own issue, so closing this one out.

nonsie’s picture

I believe it's still broken in 6.8 (don't have a clean copy atm to verify). I've modified my local copy replacing

if (isset($elements['#maxlength']) && drupal_strlen($elements['#value']) > $elements['#maxlength']) {
  form_error($elements, $t('!name cannot be longer than %max characters but is currently %length characters long.', array('!name' => empty($elements['#title']) ? $elements['#parents'][0] : $elements['#title'], '%max' => $elements['#maxlength'], '%length' => drupal_strlen($elements['#value']))));
} 

with

if($elements['#type'] != 'password_confirm') {
  if (isset($elements['#maxlength']) && drupal_strlen($elements['#value']) > $elements['#maxlength']) {
    form_error($elements, $t('!name cannot be longer than %max characters but is currently %length characters long.', array('!name' => empty($elements['#title']) ? $elements['#parents'][0] : $elements['#title'], '%max' => $elements['#maxlength'], '%length' => drupal_strlen($elements['#value']))));
  }
}

and this seems to do the trick. Since I can't find the original issue in #2 I'm not sure how it was previously fixed.

damien tournoud’s picture

The good issue for #2 is #117748: Trim required fields on validate: we added a drupal_strlen() check there, that what caused the ordering issue to appear in plain light.

#289800: Error on user creation - warning: mb_strlen() expects parameter 1 to be string, array given seems more on focus, so let's continue in there.

Status: Fixed » Closed (fixed)

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