Skip to content
Snippets Groups Projects

Issue #3260087 by DieterHolvoet, Nikhil_110, jakegibs617: Warning: mb_strlen() expects parameter 1 to be string, array given

Open Issue #3260087 by DieterHolvoet, Nikhil_110, jakegibs617: Warning: mb_strlen() expects parameter 1 to be string, array given
1 unresolved thread
1 unresolved thread

Closes #3260087

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Joshua Sedler resolved all threads

    resolved all threads

  • Steve Mokris
  • added 1 commit

    • 27d04f11 - Reused error message of the form element.

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • Joshua Sedler resolved all threads

    resolved all threads

  • Joshua Sedler resolved all threads

    resolved all threads

  • Joshua Sedler added 1 commit

    added 1 commit

    • fae394a7 - Wrap if cases in #maxlength check

    Compare with previous version

  • Alex Pott resolved all threads

    resolved all threads

  • Alex Pott added 1 commit

    added 1 commit

    • f52ea774 - Apply 1 suggestion(s) to 1 file(s)

    Compare with previous version

  • 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.

      Suggested change
      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
    Please register or sign in to reply
    Loading