Not getting values after validating a form in Entity object Doctrine

Hi, I have a post form which is not setting values in the bound entity. The code looks like below:

        $form = new PostForm;
        // postfieldset constructor has parent::__construct('post');
        $form->add( new PostFieldset() );
        $form->setHydrator( \Doctrine\Laminas\Hydrator\DoctrineObject::class);
        $request    = $this->getRequest();
        // post entity with two fields only title and description
        $postEntity = new \Application\Entity\Post();
        
        $form->bind($postEntity);
        
        if ($request->isPost()) {
            $form->setData($request->getPost());
            if ($form->isValid()) {
                var_dump($postEntity->getTitle());
            }
        }

//------- Form ----- //
use Laminas\Form\Form;

class PostForm extends Form{
    public function __construct($name = 'create-post')
    {
        parent::__construct($name);
        
        $csrf = new Element\Csrf('csrf');
        $this->add($csrf);
        
        $submitElement = new Element\Button('submit');
        $submitElement
        ->setLabel('Create')
        ->setAttributes(
            [
                'type'  => 'submit',
            ]
        );
        
        $this->add(
            $submitElement,
            [
                'priority' => -100,
            ]
        );
    }
}
//-------FieldSet Class ---------
use Laminas\Form\Fieldset;
use Laminas\InputFilter\InputFilterProviderInterface;
use Laminas\Form\Element;

class PostFieldset extends Fieldset implements InputFilterProviderInterface
{

    public function __construct()
    {
        parent::__construct('post');
        $this->add([
            'name'       => 'title',
            'options'    => [
                'label' => 'Title',
            ],
        ]);
        
        $this->add([
            'name'       => 'created_at',
            'type'       => Element\Date::class,
            'options'    => [
                'label' => 'Created At',
            ],
        ]);
        
        $this->add([
            'name'       => 'description',
            'type'       => Element\Textarea::class,
            'options'    => [
                'label' => 'Description',
            ],
        ]);
    }

    /**
     * @return array
     */
    public function getInputFilterSpecification()
    {
        return [
            'title' => [
                'required' => true,
            ],
            'description'  => [
                'required' => true,
            ],
            'created_at'  => [
                'required' => true,
            ],
        ];
    }

}
//----- Post Entity

/**
 * @ORM\Entity
 * @Gedmo\Loggable
 * @ORM\Table(name="posts")
 */
class Post
{
    
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer", options={"unsigned"=true})
     */
    private $id;
    
    /**
     * @Gedmo\Versioned
     * @ORM\Column(type="string", length=255)
     */
    private $title;
    
    /**
     * @Gedmo\Versioned
     * @ORM\Column(type="text")
     */
    private $description;
    
    /**
     * @Gedmo\Timestampable(on="create")
     * @ORM\Column(type="datetime")
     */
    private $created_at;
}

//--- Returned data from $this->getRequest()->getPost()

Laminas\Stdlib\Parameters Object
(
    [storage:ArrayObject:private] => Array
        (
            [csrf] => csrf-value
            [post] => Array
                (
                    [title] => My first doctrine post in Laminas
                    [created_at] => 2021-02-03
                    [description] => My first doctrine post in Laminas
                )

            [submit] => 
        )

)

Thanks in advance!

Without any further code it is very difficult to help here, because no one is a magician or wizard. :wink:
Please provide the form, the fieldset and the data of your request.

Hi @froschdesign,

Edited my question and given code for Action, Form, Fieldset, Entity and data returned. Sorry for not providing it first up. Thanks!

The first problem I see: the hydrator is added to the form but all related form elements are in the fieldset.

Thanks @froschdesign. Your answer was right on the money. Instead of setting doctrine hydrator in form, setting it in post fieldset solved the problem.

$postFieldObj = new PostFieldset();
$postFieldObj->setHydrator( \Doctrine\Laminas\Hydrator\DoctrineObject::class);
$form->add( $postFieldObj );

Please check also the tutorial in the documentation of laminas-form, how a form can be used in laminas-mvc based application:

https://docs.laminas.dev/laminas-form/application-integration/usage-in-a-laminas-mvc-application/