php - Symfony2: Create two controllers one to display a form and other to handle the submission -


hi new symfony2 mvc framework. have achieved far rendering form in twig template using twig template. want next create second (separate) controller deal form submission. can share me how achieve this.

i have read symfony2 documentation however, not working.

many thanks:)

you need set action on form generating so:

public function generatesearchbaraction() {     $form = $this->createformbuilder()         //this defining target route         ->setaction($this->generateurl('route_to_catch_the_request'))         ->setmethod('post')         ->add('keyword')         ->getform()     ;      return $this->render('search_bar.html.twig', array(         'form' => $form->createview()     )); } 

the controller provided @ route_to_catch_the_request can catch request.

public function showsearchkeywordsaction(request $request) {     $form->handlerequest($request);     if ($form->isvalid()) {          //do whatever...     } } 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -