TYPO3 form validation not working if only radio buttons are used -
i have trouble multistep form because validation single step contains form radio buttons not working :(
i have simple property type represent radio button value:
class step1data extends \typo3\cms\extbase\domainobject\abstractentity { /** * type * * @var string * @validate notempty */ protected $type; /** * returns type * * @return string $type */ public function gettype() { return $this->type; } /** * sets type * * @param string $type * @return void */ public function settype($type) { $this->type = $type; } }
the fluid mark-up looks follows step:
<f:layout name="default" /> <f:section name="main"> <f:form action="step1redirect" class="step1" name="step1data" object="{step1data}"> <f:render partial="formerrors" arguments="{field: 'step1data.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>
the controller actions step are:
/** * step1 * * @param \fox\example\domain\model\step1data $step1data * @ignorevalidation $step1data */ public function step1action(\fox\example\domain\model\step1data $step1data = null) { if ($globals['tsfe']->fe_user->getkey('ses', 'step1data') && $step1data == null) { $step1data = unserialize($globals['tsfe']->fe_user->getkey('ses', 'step1data')); } $this->view->assign('step1data', $step1data); } /** * step1 redirect action * * @param \fox\example\domain\model\step1data $step1data */ public function step1redirectaction(\fox\example\domain\model\step1data $step1data) { $globals['tsfe']->fe_user->setkey('ses', 'step1data', serialize($step1data)); $globals['tsfe']->fe_user->storesessiondata(); $this->redirect('step2'); }
if add example second property name of type string notempty annotation , fluid textfield form like:
<f:layout name="default" /> <f:section name="main"> <f:form action="step1redirect" class="step1" name="step1data" object="{step1data}"> <f:render partial="formerrors" arguments="{field: 'step1data.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> <!-- example second property --> <f:render partial="formerrors" arguments="{field: 'step1data.name'}"/> <f:form.textfield property="name" /> <!-- example second property --> <f:form.submit value="next" /> </f:form> </f:section>
the validation working. validation works if have textfield on form, if have radio buttons without textfield on form validation not working , error appears because step1data object null.
i don't know reason weird problem, hope can me?
the solution hidden input field above radio buttons same property name:
<f:form.hidden property="type" /> <div class="group-block"> <label> <f:form.radio property="type" value="wish1" /> type1 </label> </div> <div class="group-block"> <label> <f:form.radio property="type" value="wish2" /> type2 </label> </div>
so firstly hidden field checked , validated , if radio button checked type property overwritten
Comments
Post a Comment