Symfony Forms: split a submitted domain-name in second- and toplevel-part and save it into the model
<p>first of all, sorry for the little meaningful headline. I didn't find a better one to describe the problem.</p>

<p>I'm working on a legacy php-application which we are migrating to symfony2 with doctrine step by step. 
We have a database-table which contains domain-names. The corresponding Toplevel-Domain (e.g. com) is also stored in this table and acts as a foreign key to a ToplevelDomain-Table.</p>

<p>The first problem is that the table contains the tld twice, first in the domain and second as the foreign key to the other table. I would solve this by removing the TLD from the rest of the domain.</p>

<p>The main Problem here is the handling of form-submissions: 
I just want to submit the whole domain-name without an extra tld-field. I guess I would have to implement a custom type and work with form-events to parse the domain-name.</p>

<p>Here's very simplified example:</p>

<p>Doctrine Model, just the relevant Parts:</p>

<pre><code>/**
 * @ORM\ManyToOne(targetEntity="ToplevelDomain")
 * @ORM\JoinColumn(name="toplevelDomain")
 **/
private $toplevelDomain;

/**
 * Domainname without tld
 *
 * @ORM\Column(type="string",name="domain_name") 
 */
private $domainName;
</code></pre>

<p>Now I want to have a form field with one domain-field like this:</p>

<pre><code>$form-&gt;add('domain');
</code></pre>

<p>The form should into the domain-name and the tld, and set both in the domain-model.</p>

<p>If you have any thoughts or ideas about that, I would appreciate it. I will keep digging into this and post the solution, as soon as I have one.</p>

<p>Thank you</p>