symfony - Pre-filling form data -


i have form using symfony2. here excerpt:

$comment = new comment(); $form = $this->createformbuilder($comment)     ->add('user_id', 'hidden')     ->add('node_id', 'hidden')     ->add('comment', 'textarea', [         'attr' => [             'style' => 'width:100%; background-color:inherit; color:white;',                 'rows' => '5'             ]         ])     ->add('save', 'submit', ['label' => 'send'])     ->getform(); 

(note, these of fields, keep short.

then prefill of data in form.

$form->get('user_id')->setdata($user_id); $form->get('node_id')->setdata($video->getid()); 

but when load page, , fill out comment field , submit, error user_id , node_id haven't been filled out.

what should these? how should render them? can render them these preset values?

well, stupid of me, i'll resist urge delete, , answer instead.

if setting values in controller, don't bother having them in form @ all.

$comment = new comment(); $comment->setnodeid($video->getid()); $comment->setuserid($user_id);  $form = $this->createformbuilder($comment)     ->add('comment', 'textarea', [         'attr' => [         'style' => 'width:100%; background-color:inherit; color:white;',             'rows' => '5'         ]     ]) ->add('save', 'submit', ['label' => 'send']) ->getform(); 

in other words, set values directly on object instead, , leave form out of it. leave values need come user.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -