Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken behavior of the Phalcon\Forms\Form::getMessages #13294

Closed
sergeyklay opened this issue Feb 5, 2018 · 1 comment
Closed

Broken behavior of the Phalcon\Forms\Form::getMessages #13294

sergeyklay opened this issue Feb 5, 2018 · 1 comment
Assignees
Labels
bug A bug report status: medium Medium
Milestone

Comments

@sergeyklay
Copy link
Contributor

Validation messages, up to the #12466 PR, were added in sorted form (by element name) to the Phalcon\Forms\Form stack.

Messages generated by all the elements in the form were joined by default so they can be traversed by a single foreach.

if (!$form->isValid($_POST)) {
    $messages = $form->getMessages();

    // Default behavior
    // $messages is a Phalcon\Validation\Message\Group object
    foreach ($messages as $message) {
        echo $message, "<br>";
    }
}

The user could change this behavior to get the messages separated by the field.

foreach ($form->getMessages(true) as $attribute => $messages) {
    echo "Messages generated by ", $attribute, ":", "\n";

    // $messages is an array of Phalcon\Validation\Message\Group objects
    foreach ($messages as $message) {
        echo $message, "<br>";
    }
}

In the #12466 PR, this behavior was been broken.

// cc @mbrostami

@sergeyklay sergeyklay added this to the 3.3.x milestone Feb 5, 2018
@sergeyklay sergeyklay self-assigned this Feb 5, 2018
This was referenced Feb 5, 2018
@mbrostami
Copy link
Contributor

mbrostami commented Feb 5, 2018

@sergeyklay
I fixed that in : #13295
But I suggest to remove that part, in next major version.

I prefer to use:

        $elements = $form->getElements();
        foreach ($elements as $element) {
            echo "Messages generated by ", $element->getName(), ":", "\n";
            foreach ($form->getMessagesFor($element->getName())) as $message) {
                echo $message, "<br>";
            };
        }

@niden niden added bug A bug report status: medium Medium and removed Bug - Medium labels Dec 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug report status: medium Medium
Projects
None yet
Development

No branches or pull requests

3 participants