php - How to get data from a form who using method GET -


i have problem form. tried value form no result. form is:

<form action="{{ path('show_product_category',{ 'id':category.getid(), 'name':category.getcategorylink() }) }}" method="get" {{ form_enctype(form) }}>    {{ form_widget(form) }}    <input type="submit" class="btn btn-primary marg-left-20" value="search"/> </form> 

my controller :

$entity = new product();     $form = $this->createform(new producttype(), $entity);     $request = $this->getrequest();     $form->handlerequest($request);      //get filter array search     if ($form->isvalid()) {         $afilter['iminprice'] = $form["min_price"]->getdata();         $afilter['imaxprice'] = $form["max_price"]->getdata();     }     print_r($afilter); 

my productrepository:

 public function buildform(formbuilderinterface $builder, array $options) {     $builder->add('min_price', 'text', array('mapped' => false, 'label' => 'from :', 'attr'=>                                        array(                                             'placeholder'=>'max price',                                             'class'=>'form-control')))              ->add('max_price', 'text', array('mapped' => false, 'label' => 'to :' , 'attr'=>                                         array(                                             'placeholder'=>'minim price',                                             'class'=>'form-control')))              //->add('colors', 'choice', array('mapped' => false, 'choices' => colors::getcolors(), 'multiple' => true, 'expanded' => true))     ; } 

afilter null if using post method in afilter value form. please me!

the method in form configuration needs match method of http request. default, forms use post method, need tell use get.

put in buildform() method:

$builder->setmethod('get'); 

then in twig template, can use form_start() function , automatically set method get.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -