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

sergeyklay opened this Issue Feb 5, 2018 · 1 comment


None yet
2 participants

sergeyklay commented Feb 5, 2018

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 mbrostami referenced this issue Feb 5, 2018


Fix broken form getMessages #13295

3 of 3 tasks complete

This comment has been minimized.


mbrostami commented Feb 5, 2018

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>";

@sergeyklay sergeyklay closed this Feb 6, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment