Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2, How to add a hidden date type field to a form?

Tags:

php

symfony

I am trying the scenario below :

In myclassType

public function buildForm(FormBuilder $builder, array $options)
{
    $builder
        ->add('day','hidden')
        ->add('date', 'hidden' ) 
        ->add('hours')
        ->add('comment','textarea')
    ;
}

In myclass

class myclass
{
    //.. Other stuff

    /**
     * @ORM\Column(type="date")
     *
     * @var date $date
     */
    protected $date;
}

While rendering I get this error :

An exception has been thrown during the rendering of a template ("Catchable Fatal Error:
 Object of class DateTime could not be converted to string in 
C:\wamp\www\PMI_sf2\app\cache\dev\twig\fb\40\8957f80f2358a6f4112c3427b387.php line 684") in
 form_div_layout.html.twig at line 171.

Any idea how I can make a Date type field hidden !??

like image 415
pmoubed Avatar asked May 22 '12 20:05

pmoubed


1 Answers

Form

$builder
    ->add('day','hidden')
    ->add('date',null,array( 'attr'=>array('style'=>'display:none;')) )
... 
like image 69
a.aitboudad Avatar answered Sep 22 '22 00:09

a.aitboudad