Facebook
From Mammoth Pelican, 2 Years ago, written in PHP.
Embed
Download Paste or View Raw
Hits: 97
  1. <?php
  2.  
  3. namespace App\Controller;
  4.  
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\Form\Extension\Core\Type\TextType;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Symfony\Component\Validator\Constraints\Length;
  11.  
  12.  
  13. class SearchController extends AbstractController
  14. {
  15.     /**
  16.      * @Route("/search",name="search",methods={"get"})
  17.      * @param Request $request
  18.      * @return Response
  19.      */
  20.     public function search(Request $request): Response
  21.     {
  22.         $formBuilder = $this->createFormBuilder(null, [
  23.             'action' => '/search',
  24.             'method' => 'GET',
  25.         ]);
  26.  
  27.         $form = $formBuilder
  28.             //->setMethod('GET')
  29.             ->add('name_1', TextType::class, [
  30.                 'constraints' => [new Length(['min' => 3])],
  31.             ])
  32.             ->add('name_2', TextType::class, [
  33.                 'constraints' => [new Length(['min' => 3])],
  34.             ])
  35.             ->getForm();
  36.  
  37.         //$request = Request::createFromGlobals();
  38.         //dd($request->query->all());
  39.  
  40.         $form->handleRequest($request);
  41.  
  42.         if ($form->isSubmitted() && $form->isValid()) {
  43.             $data = $form->getData();
  44.             dd($data);
  45.         } else {
  46.             //dd($form->getErrors());
  47.         }
  48.         dd(':(');
  49.     }
  50. }