Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Form
- use Symfony\Component\Form\Extension\Core\Type\TextType;
- use Symfony\Component\Form\Extension\Core\Type\SubmitType;
- $form = $this->createFormBuilder()
- ->setMethod('GET')
- ->add('search', TextType::class)
- //->add('submit', SubmitType::class) //nije preporucljivo
- ->getForm();
- return $this->render('CarBundle:Default:index.html.twig',
- [
- 'cars' => $cars,
- 'form' => $form->createView()
- ]
- );
- **************
- form-a u view
- {{ form_start(form, { attr: {class: 'form-inline'} }) }}
- {{ form_widget(form.search, { attr: {placeholder: 'Search'} }) }}
- <button type="submit" class="btn">Search</button>
- {{ form_end(form) }}
- ------------------------------
- in DafaultController
- public function indexAction(Request $request)
- {
- $carRepository = $this->getDoctrine()->getRepository('Car');
- $cars = $carRepository->findCarsWithDetails();
- $form = $this->createFormBuilder()
- ->setMethod('GET')
- ->add('search', TextType::class,[
- 'constraints' => [
- new NotBlank(),
- new Length(['min' => 2])
- ]
- ])
- ->getForm();
- $form->handleRequest($request);
- if($form->isSubmitted() && $form->isValid()){
- die('Form submitted')l
- }
- return $this->render('CarBundle:Default:index.html.twig',
- [
- 'cars' => $cars,
- 'form' => $form->createView()
- ]
- );
- }
- **********************
- change on View
- {{ form_errors(form.search) }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement