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

Prefill default values

Hi,

when I submit a form with some validation error, the values from request are populated to related input elements. I would like to override this behavior for some special cases, but I didn't find out which class and method I should override. Please tell me where is the method which is responsible to populate form element from request.

Thanks.



1.0k

You can use the setAttribute() method before passing the form off to the view

As an example I'll use an email element

$form->get('email')->setAttribute('name', '[email protected]');

This isn't it. Question is, how is it done, that values are already prefilled in the form after submitting on the same action. Who is doing it? Because there seems to be bug, prefilling isn't working for elements named with array (i.e. name="group[field]"). So we need to override it. This is related to https://forum.phalcon.io/discussion/2354/form-element-name. Naming with array notation is ok (element has the name rendered right), but prefilling fails for it.