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



use Phalcon\Forms\Form; use Phalcon\Forms\Element\Text; use Phalcon\Forms\Element\Hidden;

class ContactForm extends Form { public function getCsrf() { return $this->security->getToken(); }

public function initialize()


    // Add a text element to capture the 'email'
    $this->add(new Text("email"));

    // Add a text element to put a hidden CSRF
    $this->add(new Hidden("csrf"));

} what $this->setEntity($this) ?. Please help me.I do not understand, please give me an example

And what do you want to achieve?

I do not understand $this->setEntity($this); in document phalcon chapter Form. I want to example.

This sets up self as the internal entity. If you will use


it will bind data it to that form as public attributes.

I do not understand, please give me an example with detail.


Here is an example of setting POST data to the $user entity.

public function initialize(User $user, $options)

Doing the following populates the entity Models\User with $_POST data.

// within a controller
// $user is an instance of Models\User
$form->bind($this->request->getPost(), $user);

If you set any sanitizers in your form, when you bind data to the entity, the sanitizers are run first, the sanitized data is then populated into the entity, in this case Models\User.

So then you can save the entity

// within a controller
$form->bind($this->request->getPost(), $user);

if ($this->request->isPost() && $form->isValid($this->request->getPost())) {