Skip to content

Container::getValues() when !isValid #266

Closed
@redeyecz

Description

@redeyecz

Version: 3.1.1

Bug Description

When validation of form/container fails, any getValues() call after it (in onError / onValidate handlers) causes User warning

Steps To Reproduce

Presenter:

public function createComponentBug()
  {
      $form = new Form();
      $form->addText('test');
      $form->addSubmit('submit');

      $form->onValidate[] = [$this, 'onValidate'];
      $form->onValidate[] = [$this, 'onValidate2'];
      return $form;
  }

  public function onValidate(Form  $form) {
      dump('validation fail');
      $form->addError('Failed');
  }
  public function onValidate2(Form  $form) {
      dump('second validation');
      dump($form->isValid());
      dump($form->getValues());
  }

Latte:

{block content}
   {control bug}
{/block}

Outputs:

dump('validation fail') 📍'validation fail'
dump('second validation') 📍'second validation'
dump($form->isValid()) 📍false

... and triggers the warning

Screenshot_2

Expected Behavior

When validating, we usually append additional info from submitted values why the form was invalid, this makes it really awkward to use with custom validators (or when skipping netteForms.js validation for complex nested controls). I'd not expect it to throw any warnings when using getValues() with invalid form/container

Additionally, the same error occurs when the validator has second argument in it's signature!

Possible Solution

Just ... remove it? What's the point?

if ($form && $form->isSubmitted() && !$form->isValid()) {
trigger_error(__METHOD__ . '() invoked but the form is not valid.', E_USER_WARNING);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions