Question: I have an entity which has a field called end\_date which is datetime. In my symfony form I have a unbinded field which you can select an amount of days e.g 3 days, 5days, 7 days.

What i need to do is manipulate the amount of days provided by the form (which i don't want to go into the db) and do the calculations of when the end \_date would be in relation to the amount of days selected and then persist the end\_date.

What im having trouble with is how to do the data manipulation in between creating the form and persisting the entities to the db.

Here is my functionality for the form as it stands:

```
public function saveNewListing($request, $controller){
        $listing = new Listing();
        $product = new Product();
        $listing->setProduct($product);
        $product->setUser($controller->getUser());
        $form = $controller->createForm(new SellType(), $auction)->handleRequest($request);

        if($form->isValid()) {
            $em = $controller->getDoctrine()->getManager();
            $em->persist($listing);
            $em->persist($product);
            $em->flush();
            return true;
        }
        return $form;
    }

```

So inbetween binding the form data and the entities and checking if the form is valid or not, where should i manipulate the data? do i need to bind the new end\_date to the form as well? or just bind it to the entity?

Thanks

Answer: 
```
   if($form->isValid()) {
            $em = $controller->getDoctrine()->getManager();

            $days = $request->get("form")["days"] 
            //* calc end date here $endDate as \DateTime */
            $listing->setEndDate($endDate);

            $em->persist($listing);
            $em->persist($product);
            $em->flush();
            return true;
 }

```
I recommend to you to do that in callback on prePersist. This is an good practice. See there more about this <http://symfony.com/doc/current/book/doctrine.html#lifecycle-callbacks>