Reputation: 97
In fluid I have select form
<f:form action="cityList" controller="City">
<f:form.select
class="js-select"
property="city"
name="cityId"
options="{cityList}"
optionLabelField="title"
optionValueField="uid" />
<f:form.submit value="Submit" />
</f:form>
In controller
/**
* action city list
*
*
* @return void
*/
public function cityListAction()
{
$cityList = $this->cityRepository->findAll();
$this->view->assign('cityList', $cityList);
$cityData = $GLOBALS['TSFE']->fe_user->setKey('ses', 'citySessionData', $cityId);
$cityData = $GLOBALS["TSFE"]->fe_user->getKey('ses', 'citySessionData');
echo $cityData;
}
But I don't have any data. If I set manual $cityId, I have session data. How I can set city id from form to $cityId
Upvotes: 0
Views: 1790
Reputation: 2683
Your is not bound to an object so the cannot use the propery property="city" correctly. Your listAction is also not expecting to get any parameters passed to it.
Please change the ViewHelpers accordingly:
<f:form action="cityList" controller="City" objectName="filter" object="{filter}">
<f:form.select
class="js-select"
property="cityId"
options="{cityList}"
optionLabelField="title"
optionValueField="uid" />
<f:form.submit value="Submit" />
</f:form>
In the HTML output, the select field should become a name like name="tx_yourext_yourplugin[filter][cityId]"
. This is very important because otherwise the form values wont be submitted to your action.
Then change your Action:
/**
* action city list
* @param array $filter
* @return void
*/
public function cityListAction($filter = [])
{
$cityList = $this->cityRepository->findAll();
$this->view->assign('cityList', $cityList);
// Give $filter back to view so it will stay selected
$this->view->assign('filter', $filter);
$cityData = $GLOBALS['TSFE']->fe_user->setKey('ses', 'citySessionData', $filter['cityId']);
$cityData = $GLOBALS["TSFE"]->fe_user->getKey('ses', 'citySessionData');
// You shall not use echo in TYPO3
// echo $cityData;
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($cityData);
}
I did not test this!
After changing the action you must clear the cache using the installtool or reinstall the extension.
Upvotes: 0