Note that there are some explanatory texts on larger screens.

plurals
  1. POsymfony2 form abstract type send options
    primarykey
    data
    text
    <p>I am doing some forms under symfony 2.1.9 For usefull reasons, I have done a FUser class, who extends from my user entity. I have done an UserType class, for being able to reuse my form.</p> <p>My UserType class looks like this :</p> <pre><code>&lt;?php namespace CD\BoutiqueBundle\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 -&gt;add('nom', 'text') -&gt;add('prenom', 'text') -&gt;add('mail', 'text') -&gt;add('fb_id','hidden',array('data'=&gt;'null')) -&gt;add('pass', 'repeated', array('type' =&gt; 'password', 'invalid_message' =&gt; 'The password fields must match.', 'first_options' =&gt; array('label' =&gt; 'Mot de passe'), 'second_options' =&gt; array('label' =&gt; 'Confirmer le mot de passe'))) -&gt;add('tel', 'text', array('required' =&gt; false)) -&gt;add('adresse', 'text') -&gt;add('code_postal', 'text') -&gt;add('ville', 'text') -&gt;add('tel', 'text') -&gt;add('date_naissance', 'birthday', array('widget' =&gt; 'choice', 'years' =&gt; range(1933,2013,1), 'months' =&gt; range(1,12,1), 'days' =&gt; range(1,31,1))); } public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver-&gt;setDefaults(array( 'data_class' =&gt; 'CD\ConfigBundle\Entity\User' )); } public function getDefaultOptions(array $options) { return array( 'data_class' =&gt; 'CD\ConfigBundle\Entity\User', ); } public function getName() { return 'usertype'; } } </code></pre> <p>What I want to do is quite simple, but I didn't find my answer neither on google, neither on symfony doc, neither on this website. I want to send options from my controller to this UserType.</p> <p>For instance, in some case, I don't want to add "tel" and "adresse" inputs. Or sometimes, I want this input to be required, in other, I want the same input not required.</p> <p>How can I do this ?</p> <p>Thank you, </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload