I am trying to save HTML content with the Symfony2 form system but I am facing issues with escaping.
My addPost action looks like this
$em = $this->getDoctrine()->getEntityManager();
$post = new Post();
$postForm = $this->createForm(new PostFormType(), $post);
if ($request->getMethod() == 'POST') {
$postForm->bindRequest($request);
if($postForm->isValid()){
$em->persist($post);
$em->flush();
}
}
The problem is that the post form has a content textarea that allows the user to enter html. When the form is submitted with html like <a href="#">test</a> the content gets saved to the database as <a href=\"#\">test</a>. And then on each subsequent save the backslashes escape themselves again and again...
What is the proper way to store HTML with the Symfony2 form component?