# Not getting values after validating a form in Entity object Doctrine

**URL:** <https://discourse.laminas.dev/t/not-getting-values-after-validating-a-form-in-entity-object-doctrine/2090>\
**Category:** Components & MVC\
**Tags:** laminas-form, laminas-mvc, doctrine\
**Created:** [February 3, 2021, 4:15pm UTC](https://discourse.laminas.dev/t/not-getting-values-after-validating-a-form-in-entity-object-doctrine/2090 "2021-02-03T16:15:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ALTAMASH80](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/altamash80/32/895_2.png) [@ALTAMASH80](https://discourse.laminas.dev/u/ALTAMASH80)\
**Post date:** [February 3, 2021, 4:15pm UTC](https://discourse.laminas.dev/t/not-getting-values-after-validating-a-form-in-entity-object-doctrine/2090/1 "2021-02-03T16:15:43Z")

</div>

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

```auto
        $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!

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [February 3, 2021, 6:35pm UTC](https://discourse.laminas.dev/t/not-getting-values-after-validating-a-form-in-entity-object-doctrine/2090/2 "2021-02-03T18:35:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ALTAMASH80](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/altamash80/32/895_2.png) [@ALTAMASH80](https://discourse.laminas.dev/u/ALTAMASH80)\
**Post date:** [February 3, 2021, 7:30pm UTC](https://discourse.laminas.dev/t/not-getting-values-after-validating-a-form-in-entity-object-doctrine/2090/3 "2021-02-03T19:30:11Z")

</div>

Hi @froschdesign,

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

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [February 3, 2021, 7:37pm UTC](https://discourse.laminas.dev/t/not-getting-values-after-validating-a-form-in-entity-object-doctrine/2090/4 "2021-02-03T19:37:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ALTAMASH80](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/altamash80/32/895_2.png) [@ALTAMASH80](https://discourse.laminas.dev/u/ALTAMASH80)\
**Post date:** [February 4, 2021, 11:16am UTC](https://discourse.laminas.dev/t/not-getting-values-after-validating-a-form-in-entity-object-doctrine/2090/5 "2021-02-04T11:16:40Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [February 4, 2021, 11:21am UTC](https://discourse.laminas.dev/t/not-getting-values-after-validating-a-form-in-entity-object-doctrine/2090/6 "2021-02-04T11:21:18Z")

</div>

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/](https://docs.laminas.dev/laminas-form/application-integration/usage-in-a-laminas-mvc-application/)
