[Flow] How to build a search/filter form above of a list

Axel Wüstemann awu at qbus.de
Fri Nov 1 11:36:31 CET 2013


Am 31.10.2013 13:53, schrieb Bastian Waidelich:
> Axel Wüstemann wrote:
>
> Hi again,
>
>
>> how I can build a search form above of a list.
>> Forms need to containobject [...]
>
> Forms only need to be bound to an object if you want to modify that
> object. Therefor the "object" argument of the form ViewHelper is optional!
>
>
>> <f:form method="post" action="index" object="{filter}"
>> objectName="filter" enctype="multipart/form-data">
>
> Please allow me to dissect your code (not to split hairs but in order to
> understand it):

I greatly appreciate it!
>
> If the form is used only to filter a result (and has no side-effects on
> the server) you probably want to use "GET" as method.

... with up to 5 additional arguments in the url and the indexAction - 
letter would not nice ti read and to change.

I have 5 lists (see later: fishery inspections of several kinds) that 
need to be filtered - by different values.
>
> You can omit the "object" argument if {filter} is never set. But if you
> want to redisplay the filter form what you did is just fine!

Yes it needs to be redisplayed and even stored, so the once set filter 
will remain until it will be changed again.
>
> "The content type 'multipart/form-data' should be used for submitting
> forms that contain files, non-ASCII data, and binary data." [1] - you
> probably won't need that for a filter

Yes, you're right - this due to copy&paste ;=)
>
>
>> public function indexAction(array $filter = null) {
>
> This should work, but you should try to avoid array as a placeholder for
> objects. Instead you can create a simple filter "Data Transfer Object":

I tried to avoid this, because I have five types of this filter forms. I 
appreciate Flow of being very clear and elegant, but such a Data 
Transfer Object in this case seemed to me to much efford for the related 
purpose, or?
>
> <?php
> namespace Your\Package\Domain\Dto;
>
> class Filter {
>
>      /**
>       * Thats a good place to explain what the heck a "fast" should be ;)
>       *
>       * @var string
>       */
>      protected $fast;
>
>      /**
>       * @param string $fast
>       */
>      public function __construct($fast) {
>          $this->fast = $fast;
>      }
>
>      /**
>       * @return string
>       */
>      public function getFast() {
>          return $this->fast;
>      }
> }
>
>
>
> And then
>
> /**
>   * @param Filter $filter
>   */
> public function indexAction(Filter $filter = NULL) {
>   ...
> }
>
> in your controller.
>
>
>> Within my filter fields, I have selectbox 'fasts' which I initialize
>> with options.
>
> I really wonder what "fasts" should be.

This is a german abriviation from the customer's domain which I did not 
try to translate. The topic is fishery inspection and a FAST is an 
inspection vessel.
>
>
>> On submit of the search form, only this select box is set
>> in the $filter array, not other fields of the form, not the other fields
>> I filled.
>
> What other fields does your filter form contain and how does the Fluid
> template look like?

One excample
http://pastebin.com/yXA4WAGT


>
> It should be something like:
>
>
> <f:form.select property="fast" options="{fasts}" />
>
> <f:form.textfield property="slow" />
>
Yes ist is:
http://pastebin.com/yXA4WAGT

>
>
> [1] http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.2
>
>

Thank you, Bastian!

Axel


More information about the Flow mailing list