Lovely form submission mb_strlen() errors

warning: mb_strlen() expects parameter 1 to be string, array given in .../includes/unicode.inc on line 409.

This error stems from the drupal_strlen() function, which for me traced back to includes/form.inc line 695, the _form_validate() function where you see this:

if (isset($elements['#maxlength']) && drupal_strlen($elements['#value']) > $elements['#maxlength']) {

For me, it was Views exposed filters passing arrays to $elements['#value'] from Min / Max fields (exposed filters using 'between') that also had a maxlength definition. For example, a real estate site using beds & baths, min/max, you probably don't want people entering more than 2 characters for beds/baths and voila, we have this issue.

I propose this solution, simply making sure the value is not an array:

if (isset($elements['#maxlength']) && !is_array($elements['#value']) && drupal_strlen($elements['#value']) > $elements['#maxlength']) {

Since this is only here to ensure maxlength has not been exceeded (I supposed due to URL hijacking since the form fields won't allow you to type more in them?) I don't see any issues in doing so.

http://api.drupal.org/api/drupal/includes--form.inc/function/_form_valid...

Joshua Walker