Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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.



19.6k
Accepted
answer

This?

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

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

http://docs.phalconphp.com/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']); ```

http://docs.phalconphp.com/es/latest/reference/forms.html



19.6k

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']));

http://docs.phalconphp.com/en/master/api/Phalcon%5Forms%5Element%5Select.html