[TYPO3-mvc] How to send object form data in a link URL
g4-lisz at tonarchiv.ch
g4-lisz at tonarchiv.ch
Sat Sep 17 06:22:55 CEST 2011
Hi
I wrote a search form to search for domain objects by certain properties
(e.g. clients by cities).
For this reason i made the class "SearchDemand". It contains all the
properties, against which objects will be matched:
class Tx_Myext_Domain_Model_SearchDemand extends
Tx_Extbase_DomainObject_AbstractEntity {
/**
* @var Tx_Myext_Domain_Model_City The demanded City
**/
protected $city;
[etc.]
}
The controller action for the search form looks like this:
function searchformAction(Tx_Myext_Domain_Model_SearchDemand $demand=NULL) {
$this->view->assign('demand', $demand);
$this->view->assign('cities', $this->citiyRepository->findAll());
}
function resultAction(Tx_Myext_Domain_Model_SearchDemand $demand) {
$this->view->assign('clients',
$this->clientRepository->findByDemand($demand));
}
The repository's finder method looks like this:
function findByDemand(Tx_Myext_Domain_Model_SearchDemand $demand)
$query = $this->createQuery();
$constraints = array();
if ( ($city = $demand->getCity()) != NULL) {
$constraints[] = $query->equals('person.city', $city);
}
[etc.]
}
This works as expected as long i use the form viewhelper with select in
my views.
But i'd like to have a list of all cities on my search page, not a
select form. Ever city name should just be a link.
I tried something like this in the search form view:
<f:for each="cities" as="city"><a
href="{f:uri.action(action:'result',arguments:{demand:{city:city}})}">{city.name}</a></f:for>
This gave me an error: "Request hash (HMAC) checking failed. The
parameter __hmac was invalid or not set, and objects were modified."
I also tried this in my view:
<f:form action="results" object="{demand}" id="search_form">
<input type="hidden" id="input_city"
name="tx_myext_myplugin[demand][city]" value="">
<f:for each="{cities}" as="city"><a href="#"
onClick="$('#input_city').val('{city.uid}');$('#search_form').submit();">{city.name}</a></f:for>
</f:form>
No success neither.
What magic do i need to get this working?
Many thanks in advance...!
Cheers, T.
More information about the TYPO3-project-typo3v4mvc
mailing list