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)
{
$builder
->add(‘firstname’)
->add(‘lastname’)
->add(’email’)
->add(‘password’,’password’)
->add(‘status’,’hidden’,array(‘data’ => ‘0’,))
->add(’emailstatus’,’hidden’,array(‘data’ => ‘0’,))
;
}

public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
‘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 %}

 

 

Thanks

Vinod K Maurya

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s