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

Bastian Waidelich bastian at typo3.org
Thu Oct 31 13:53:38 CET 2013


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):

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.

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!

"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


> 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":

<?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.


> 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?

It should be something like:


<f:form.select property="fast" options="{fasts}" />

<f:form.textfield property="slow" />

...


HTH


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


-- 
Bastian Waidelich
--
Core Developer Team

TYPO3 .... inspiring people to share!
Get involved: typo3.org


More information about the Flow mailing list