Issue #3260087 by DieterHolvoet, Nikhil_110, jakegibs617: Warning: mb_strlen() expects parameter 1 to be string, array given
1 unresolved thread
Closes #3260087
Merge request reports
Activity
Filter activity
- Resolved by Joshua Sedler
- Resolved by Joshua Sedler
- Resolved by Julian Pustkuchen
- Resolved by Joshua Sedler
- Resolved by Alex Pott
330 330 protected function performRequiredValidation(&$elements, FormStateInterface &$form_state) { 331 // Verify that the value is not longer than #maxlength. 332 if (isset($elements['#maxlength']) && mb_strlen($elements['#value']) > $elements['#maxlength']) { 333 $form_state->setError($elements, $this->t('@name cannot be longer than %max characters but is currently %length characters long.', ['@name' => empty($elements['#title']) ? $elements['#parents'][0] : $elements['#title'], '%max' => $elements['#maxlength'], '%length' => mb_strlen($elements['#value'])])); 331 if (isset($elements['#maxlength'])) { 332 $name = empty($elements['#title']) ? $elements['#parents'][0] : $elements['#title']; 333 334 // Verify that $elements['#value'] is a string, if it is supposed to be one: 335 if (!is_string($elements['#value'])) { 336 $form_state->setError($elements, $this->t('The submitted value type %type in the %name element is not allowed.', ['%type' => gettype($elements['#value']), '%name' => $name])); 337 } 338 // Verify that the value is not longer than #maxlength. 339 elseif (mb_strlen($elements['#value']) > $elements['#maxlength']) { 340 $form_state->setError($elements, $this->t('@name cannot be longer than %max characters but is currently %length characters long.', ['@name' => $name, '%max' => $elements['#maxlength'], '%length' => mb_strlen($elements['#value'])])); 341 } 334 342 } - Comment on lines -331 to 334
The comment
// Verify that $elements['#value'] is a string, if it is supposed to be one:
does not really say any more than the code. I think if we just have one comment that this section is about max length then we are good. The stringy-ness is a detail that is well explained by the code.331 if (isset($elements['#maxlength'])) { 332 $name = empty($elements['#title']) ? $elements['#parents'][0] : $elements['#title']; 333 334 // Verify that $elements['#value'] is a string, if it is supposed to be one: 335 if (!is_string($elements['#value'])) { 336 $form_state->setError($elements, $this->t('The submitted value type %type in the %name element is not allowed.', ['%type' => gettype($elements['#value']), '%name' => $name])); 337 } 338 // Verify that the value is not longer than #maxlength. 339 elseif (mb_strlen($elements['#value']) > $elements['#maxlength']) { 340 $form_state->setError($elements, $this->t('@name cannot be longer than %max characters but is currently %length characters long.', ['@name' => $name, '%max' => $elements['#maxlength'], '%length' => mb_strlen($elements['#value'])])); 341 } 342 } 331 // Verify that the value is not longer than #maxlength. 332 if (isset($elements['#maxlength'])) { 333 $name = empty($elements['#title']) ? $elements['#parents'][0] : $elements['#title']; 334 335 if (!is_string($elements['#value'])) { 336 $form_state->setError($elements, $this->t('The submitted value type %type in the %name element is not allowed.', ['%type' => gettype($elements['#value']), '%name' => $name])); 337 } 338 elseif (mb_strlen($elements['#value']) > $elements['#maxlength']) { 339 $form_state->setError($elements, $this->t('@name cannot be longer than %max characters but is currently %length characters long.', ['@name' => $name, '%max' => $elements['#maxlength'], '%length' => mb_strlen($elements['#value'])])); 340 } 341 }
Please register or sign in to reply