@xAockd it depends on which criteria you want to sort them.
According to the documentation Phalcon form cant be sorted.
But you can sort your element before adding the to the form. See:
<?php
// firstly create an array
$listOfDinamycFormElements=array();
/* fill it dinamycally with your elements
...
$listOfDinamycFormElements[]=new Element(...);
...
*/
// now you can use php built in functions to sort arrays
// lets say you want to sort them on the alpha order
usort($listOfDinamycFormElements,function($a,$b){
return strcmp($a->getName(),$b->getName());
});
$form = new Phalcon\Forms\Form();
// finaly add them to the form
foreach($listOfDinamycFormElements as $elm){
$form->add($elm);
}
PHP sort functions : https://fr2.php.net/manual/en/array.sorting.php