title: How to map two symfony form field to one model method?
body: <p>Hi stackexchange users,</p>
  
  <p>I have a data (model) class which has two methods which look like this:</p>
  
  <pre><code> class ContactDetails {
  
      public function setWebsite($address, $type) {
       //do something...
      }
  
      public function getWebsite($type) {
       //do something...
      }
  
   }
  </code></pre>
  
  <p>Now I want to create a form where the user can input a website address and choose a type (e.g. "private" or "business") for the address.</p>
  
  <p>To make this possible I have created a custom form type like this</p>
  
  <pre><code>class ContactDetailsType extends AbstractType {
  
      public function buildForm(FormBuilderInterface $builder, array $options) {
          $builder
          -&gt;add('type', 'text') //better: choice, but for the sake of demo...
          -&gt;add('website', 'text')
          ;
  
      }
  
      public function getName() {
          return 'ContactDetailsType';
      }
  
      public function setDefaultOptions(OptionsResolverInterface $resolver) {
          $resolver
          -&gt;setDefaults(array(
                  'data_class' =&gt; 'ContactDetails',
          ));
      }
  }
  </code></pre>
  
  <p>The controller then looks like this:</p>
  
  <pre><code>public function indexAction(Request $request) {
      //generate completely new cost unit
      $costunit = new ContactDetails();
  
      //generate form
      $form = $this-&gt;createForm(new ContactDetailsType(), $costunit);
      $form-&gt;add('save', 'submit');
  
      $form-&gt;handleRequest($request);
  
      if ($form-&gt;isValid()) {
          //yay!
      }
  
  }
  </code></pre>
  
  <p>This obviously doesn't work, as the form component doesn't know how to map these two fields from the type to the data model class.</p>
  
  <p>Question: What is the best practise to map the data of two fields of a form to one method call in a data model class and vice-versa?</p>