We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Best practices to handle forms in Phalcon Php

Hi there,

As a new beginner in Phalcon Php, i was wondering what's the best pratices to handle forms and validation components in the MVC. I used to work with Zend Framework, and Code Igniter before, and started to hear a lot about Phalcon.

Forms are common components in a web application, and i'd like to know what's your best purpose to handle them in Phalcon.

For the time, my application folder is set like this : https://docs.phalcon.io/en/latest/reference/tutorial.html#file-structure. I also have a "config" folder in the app one.

If i want to use many forms like "login", "register" etc. What do you advice me ? Creating a "helper" folder ? Sets a config file where all forms validation rules are sets (like CodeIgniter) ?

The goal is to have an easy way to manage all the forms in the application, just construct them in controllers, and check if their valids. Sorry for my bad spelling, i'm french :o)



Check out the vokuro project the phalcon team did. https://github.com/phalcon/vokuro/tree/master/app

It uses form classes to define how the inputs should render, and then uses the form class to validate in the controller. Inspect the session controller and the register/login forms that accompany it to give you a good idea of how to set it up.

Then when you are comfortable with phalcon form generation and are interested in more dynamic form inputs they give a good example in the wiki on how to do a dependant drop down: and fill dynamically from other models: https://github.com/phalcon/cphalcon/wiki/Dependent-Select-Dropdown


Sounds great :-) Thank you David.