[TYPO3-mvc] validating two model in a form

Franz Koch typo3.RemoveForMessage at elements-net.de
Thu Nov 4 12:10:13 CET 2010


Hey,

> Can anyone help me in validating two models in single form eg
>
> suppose i have two table
> 1 ) student (id,name,age)
> 2) Address (student_id,city,state,pincode)
>
>
> and i have a form like this
>
> <f:form method="post" controller="Student" action="create"
> name="student" object="{student}" >
> <f:form.textbox property="name" />
> <f:form.textbox property="age" />
> <f:form.textbox property="city" />
> <f:form.textbox property="state" />
> <f:form.textbox property="pincode" />
> <f:form.submit class="submit" value="Create Master Template"/>
> </f:form>
>
> from this form i want to validate (name and city ) which are in two
> different model
>
> is it possible to validate 2 fields in different model or am i doing it
> in wrong way ?

well, your student doesn't have a property "city" or "state", so you 
can't use your template as is currently. Your student most likely has a 
property "address" which itself has the properties "city" and "state". 
So you have to reflect that in your template in order to get the values 
mapped to the according address model:

<f:form.textbox property="address.city" />

Once you changed the template accordingly, extbase should at least 
create a student object with according address object and validate the 
student model (if the properties of the student model have correct 
annotations). The auto-validation of child objects is still a issue of 
extbase. IIRC this did not work a few months ago and a ticket has been 
created for that - not sure if current SVN version already has that 
feature. Please have a look at the bugtracker on forge.

-- 
kind regards,
Franz Koch


More information about the TYPO3-project-typo3v4mvc mailing list