Symfony form solution

Some time we need from field  should be exist but  don’t  want to show  form field on from and  default value should be post and value should be inserted.

Like Status, Email status

namespace Profile\RegisterBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class UserType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
->add(‘status’,’hidden’,array(‘data’ => ‘0’,))
->add(’emailstatus’,’hidden’,array(‘data’ => ‘0’,))

public function setDefaultOptions(OptionsResolverInterface $resolver)
‘data_class’ => ‘Profile\RegisterBundle\Entity\User’

public function getName()
return ‘profile_registerbundle_usertype’;


Check session in  twig fIle

{% if userlogin|default is empty %}
<li><a href=”/profile/login/”>Login </a></li>
{% else %}
<li><a href=”/profile/login/logout/”>logout </a></li>
{% endif %}




Vinod K Maurya


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s