Reputation: 1
I'm new to Symfony.I made a form with insert,delete,view,update. In view page i added a edit button which is used to update the values.when i submit the form after change the values in form values will not updated in output.Please share your thoughts.
Thank You...
here i attached my controller code
/**
* @Route("/update/{id}", name="update")
*/
//edit function
public function edit($id,Request $request,Ramsurath $ramsurath) :Response
{
$form = $this->createForm(RamsurathType::class, $ramsurath);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid())
{
$this->getDoctrine()->getManager()->flush();
return $this->redirectToRoute('index');
}
return $this->render('ramsurath/update.html.twig',
['ramsurath'=>$ramsurath,'form' => $form->createView()]);
}
Upvotes: 0
Views: 121
Reputation: 1130
See the Symfony Documentation for Processing Forms.
You are missing the call to $form->getData()
before flushing:
/**
* @Route("/update/{id}", name="update")
*/
//edit function
public function edit($id,Request $request,Ramsurath $ramsurath) :Response
{
$form = $this->createForm(RamsurathType::class, $ramsurath);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid())
{
$ramsurath = $form->getData(); // this is the line you are missing
$this->getDoctrine()->getManager()->flush();
return $this->redirectToRoute('index');
}
return $this->render('ramsurath/update.html.twig',
['ramsurath'=>$ramsurath,'form' => $form->createView(),
]);
}
Upvotes: 2