0

I have a (hopefully) simple problem:

I want to use a simple html form in a sympony2 project. The Problem is, that noting is sent by get through the form.

The Url after sending the form is: localhost:8888/de/search_art?

you see... there is no string after the ? !!!

The form looks like this:

<form class="navbar-form" role="search" method="get" action="{{ path('func_search_art') }}">
          <input type="text">
          <button type="submit" class="btn btn-default">Send</button>
</form>

This is my routing:

func_search_art:
    path:     /search_art/
    defaults: { _controller: FuncSearchBundle:Search:SearchArt }

I don't want to do something within a controller for it, because it is in the navbar and for this it has to appear in every page. I don't want to initialize a form variable in every controller of the page for a simple navbar search field.

Is there a possiblity to create a simple form like this in symfony2 without using a form builder and so on ... ?

Greetz Michael

3 Answers 3

1

Yes, you can safely keep your form written in twig in the form you presented it. No need to create a form builder in every controller and send the form to twig. The only place you will have to build it is the SearchArtAction method from SearchController, where you have the handling functionality for this form.

Also you need to give a name to your text input.

<form class="navbar-form" role="search" method="get" action="{{ path('func_search_art') }}">
      <input type="text" name="q">
      <button type="submit" class="btn btn-default">Send</button>
</form>
Sign up to request clarification or add additional context in comments.

Comments

1

Because your input lacks the name attribute , which is the relevant attribute to create the post data/query string.

Comments

0

You can't it will give you: "The CSRF token is invalid. Please try to resubmit the form". Regardless of that it actually work without it. For some reason Symfony serialized the forms. I particularly hate the fact that I need the form object to use forms, in many cases I found it overkill. Your $form->isValid will also failed, but the $form->isSubmitted() will not. One of the reasons I hate the form object is how tedious it is to populate a drop down with an EntityType, instead of making simple symfony manage to make the process a damn nightmare.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.