We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Array notation in naming Form elements

This code:

$p_birthdate = new Text('p_birth_date[]');

$p_birthdate->addValidators(array(

            new PresenceOf(array(
                'message' => 'Birth date is not valid.'
            ))
));

$this->add($p_birthdate);

Renders HTML as it should be:

<input type="text" name="p_birth_date[]" value="1964-10-16" class="form-control birthDate" data-date-format="yyyy-mm-dd">

But validation is a problem. Form is never valid.

if ($f->isValid($this->request->getPost()) == false) {
            foreach ($f->getMessages() as $message) {
                $messages[$message->getField()] = $message->getMessage();
            }

            $this->view->errors = $messages;
}

All fileds with name that is array are marked as invalid.

How to do debug of this isValid method?

Maybe i am doing this wrong way.

I would appreciate some answers.

edited Sep '14

It's been 17 days and you probably found the solution but for others:

Instead of this: $p_birthdate = new Text("p_birth_date[]"); you should do this: $p_birthdate = new Text("p_birth_date",array("name" => "p_birth_date[]"));, note that the name in the php form object is "p_birth_date" (no square brackets) while the name in the html form field is "p_birth_date[]".