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

Form, get passed values if one field failed

I have a form:

name1 = a

name2 = b

date = sdfsdf

"date" is obviously bad, so ->isValid() will fail. But name1, name2 is ok. How to get their values? I only can see their "default" value



28.1k

so, in other words: while adding form elements, I want something like that:

$item = new \CoreExt\Form\Element\Text('name');

$item->setDefault($item->getValue());

You don't need to do antyhing. Phalcon handles this for you:

{{ form.label('names') }}
{{ form.render('names') }}
{{ form.messages('names') }} 

The above code will generate the input, its label, will print errors and will auto populate input on form fail.

More info from the docs: https://docs.phalcon.io/en/latest/reference/forms.html