Symfony2 confirmation form without class

I am trying to create a search form without an entity.

Controller:

public function SearchFormAction() { $collectionConstraint = new Collection(array( 'size' => new MinLength(3), )); $searchform = $this->createFormBuilder(null, array( 'validation_constraint' => $collectionConstraint, )) ->add('min_range') ->add('max_range') ->add('bedrooms') ->add('bathrooms') ->add('size') ->add('user') ->getForm() ; return $this->render("RealBundle:User:search.html.twig", array( 'searchform' => $searchform->createView(), )); } 

View:

 <div id="dialog" title="Advanced Search"> <form action="{{ path('searchresults') }}" method="post" {{ form_enctype(searchform) }} id="frmSearch"> <fieldset> <h3>Properties</h3> <div class="form-search-item"> {{ form_label(searchform.min_range, 'Price Range') }} {{ form_widget(searchform.min_range) }} to {{ form_widget(searchform.max_range) }} {{ form_widget(searchform.min_range) }} </div> <div class="form-search-item"> {{ form_label(searchform.bedrooms, 'Bedrooms') }}: {{ form_widget(searchform.bedrooms) }} </div> <div class="form-search-item"> {{ form_label(searchform.bedrooms, 'Bathrooms') }}: {{ form_widget(searchform.bathrooms) }} </div> <div class="form-search-item"> {{ form_label(searchform.bedrooms, 'Size') }}: {{ form_widget(searchform.size) }} </div> <h3>User</h3> <div class="form-search-item"> {{ form_label(searchform.user, 'User') }}: {{ form_widget(searchform.user) }} </div> {{ form_rest(searchform) }} <input type="submit" value="Search"> </fieldset> </form> 

I tried other checks like MinLength, MaxLenght, Type and nothing works for me, what am I doing wrong? I want to check the range, bedrooms, bathrooms, size as integers and minimum for the user.

Tnx and sorry for my english.

+1
source share
1 answer

Your check seems to work in my test. But there are no error messages in the template.

You need

 {{ form_errors(form) }} 

to display global errors, and then for each field you can display your errors, for example

 {{ form_errors(form.size) }} 

Then, as if by magic, you should see your error messages. Although I have not seen your controller, I cannot be sure that you are binding and calling isValid.

If you still have problems, send your controller too.

+2
source

Source: https://habr.com/ru/post/1496150/


All Articles