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 how to add related elements

Hello Guys,

I am pretty new to the Phalcon, mostly worked with Symfony2 where form builder was awesome.

Can someone just lead me to the answer, that how can we add entity element to the form.

Let's suppose I have a campaign form, there I need to select countries/languages/domains lists. How can it be done?

Thanks in advanced.



33.8k
Accepted
answer

This?

$form = new Phalcon\Forms\Form();

$form->add(new Select('languages', ['EN' => 'English']);

https://docs.phalcon.io/es/latest/reference/forms.html

Thanks, The thing I was missing to put entity name, it fixed now.

$category = new Select('category_id', Categories::find(), [ 'using' => ['id', 'name'], 'useEmpty' => true, 'emptyText' => '...', 'emptyValue' => '' ]);

This?

$form = new Phalcon\Forms\Form();

$form->add(new Select('languages', ['EN' => 'English']);

https://docs.phalcon.io/es/latest/reference/forms.html



33.8k

The name is the first param always when creating a tag. The ID will be the same as the name until you specify it:

$form->add(new Select('languages', ['id' => 'myLanguagesSelect'], ['EN' => 'English']));

https://docs.phalcon.io/en/master/api/Phalcon_Forms_Element_Select.html