[TYPO3-dev] Formular Validierung unwirksam?
Ronny Hauptvogel
rh at level-pro.de
Tue Jul 14 21:19:10 CEST 2015
Hi,
ich habe ein Problem mit einem Multistep-Formular und zwar wird die Validierung via @validate-Annotation nicht vorgenommen, wenn ein Fluid-Formular nur Radio-Buttons enthält.
Erläuterungen:
Die Radio-Buttons werden durch die Property: type repräsentiert, welche anschließend als Container für den ausgewählten Wert genutzt wird. Dazu habe ich folgende Klasse erstellt:
class Step1 extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
/**
* type
*
* @var string
* @validate NotEmpty
*/
protected $type;
/**
* Returns the type
*
* @return string $type
*/
public function getType() {
return $this->type;
}
/**
* Sets the type
*
* @param string $type
* @return void
*/
public function setType($type) {
$this->type = $type;
}
}
Das Fluid-Layout, welches für die Ausgabe dieses Steps verantwortlich ist, enthält 2 Radio-Buttons und einen Submit-Button und beide Radio-Buttons sind initial nicht gesetzt:
<f:layout name="Default" />
<f:section name="main">
<f:form action="step1redirect" name="step1" object="{step1}">
<f:render partial="FormErrors" arguments="{field: 'step1.type'}" />
<label>
<f:form.radio property="type" value="type-1" />
type 1
</label>
<label>
<f:form.radio property="type" value="type-2" />
type 2
</label>
<f:form.submit value="next" />
</f:form>
</f:section>
Die Controller-Actions sind wie folgt aufgebaut:
/**
* Step1
*
* @param \Example\Example\Domain\Model\Step1 $step1
* @ignorevalidation $step1
*/
public function step1Action(\Example\Example\Domain\Model\Step1 $step1 = NULL) {
if ($GLOBALS['TSFE']->fe_user->getKey('ses', 'step1') && $step1== NULL) {
$step1 = unserialize($GLOBALS['TSFE']->fe_user->getKey('ses', 'step1'));
}
$this->view->assign('step1', $step1);
}
/**
* Step1 redirect action
*
* @param \Example\Example\Domain\Model\Step1 $step1
*/
public function step1redirectAction(\Example\Example\Domain\Model\Step1 $step1) {
$GLOBALS['TSFE']->fe_user->setKey('ses', 'step1', serialize($step1));
$GLOBALS['TSFE']->fe_user->storeSessionData();
$this->redirect('step2');
}
An sich eigentlich nichts spektakuläres, allerdings scheint die NotEmpty-Validierung nicht zugreifen, solange ich nur die Radio-Buttons in diesem Fluid-Formular habe. Denn sobald ich dieses absende, erhalte ich eine Fehlermeldung, dass das Objekt Step1 nicht gesetzt ist, was verständlich ist, da kein Radio-Button ausgewählt wurde und somit die Property: type nicht gesetzt wurde. Wenn ich das Fluid-Formular und die Klasse jedoch um ein Textfeld und eine weitere Property erweitere oder die Property: type direkt an eine Fluid-Textfeld binde, funktioniert die Validierung wie gewünscht.
Dazu folgende 2 funktionierende Beispiele, welche auf den oberen Code-Schnipseln aufbauen:
Beispiel 1: Fluid-Formular mit Textfeld
<f:layout name="Default" />
<f:section name="main">
<f:form action="step1redirect" name="step1" object="{step1}">
<f:render partial="FormErrors" arguments="{field: 'step1.type'}" />
<f:form.textfield property="type" />
<f:form.submit value="next" />
</f:form>
</f:section>
Beispiel 2: Fluid-Formular mit Textfeld + Radio-Buttons:
<f:layout name="Default" />
<f:section name="main">
<f:form action="step1redirect" name="step1" object="{step1}">
<f:render partial="FormErrors" arguments="{field: 'step1.type'}" />
<label>
<f:form.radio property="type" value="type-1" />
type 1
</label>
<label>
<f:form.radio property="type" value="type-2" />
type 2
</label>
<!-- property: name ist genauso aufgebaut, wie property: type -->
<f:render partial="FormErrors" arguments="{field: 'step1.name'}"/>
<f:form.textfield property="name" />
<f:form.submit value="next" />
</f:form>
</f:section>
Ich weiß einfach nicht, warum die Validierung für ein Formular, welches nur Radio-Buttons enthält nicht funktioniert und hoffe ihr könnt mir weiterhelfen :)
More information about the TYPO3-dev
mailing list