form api

Lovely form submission mb_strlen() errors

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

This error stems from the drupal_strlen() function, which for me traced back to includes/ 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: