[TYPO3-mvc] create two objects with one form and validation
Thomas Allmer
at at delusionworld.com
Fri Mar 23 15:16:12 CET 2012
hey,
I need a form that creates two separate objects. Well I though that
shouldn't be too hard :p
Class: Obj1
-> name: string (notEmpty)
-> points: int (notEmpty)
Class: Obj2
-> age: float (notEmpty)
for one Object it's pretty easy :p
<f:form action="create" name="newObj1" object="{newObj1}">
<f:form.textfield property="name" />
<f:form.textfield property="points" />
</f:form>
now if I want both objects in the same form I just create a Class to
hold them both right?
Class: Obj1AndObj2
-> obj1
-> obj2
<f:form action="create" name="newObj1AndObj2" object="{newObj1AndObj2}">
<f:form.textfield property="obj1.name" />
<f:form.textfield property="obj1.points" />
<f:form.textfield property="obj2.age" />
</f:form>
I do get both objects and the data, but it won't validate... meaning if
I just fill out obj1.name it still gets into the createAction and won't
throw an error that points (and age) should not be empty.
I then tried to create my own Model Validator
Obj1AndObj2Validator
in it I check for the correct class
if ($obj1AndObj2->getObj1() instanceof Obj1) {
but yeah it is correct... it just isn't "valid" in teams of it extbase
properties...
so how can I validate an object like extbase does? I tried
"Tx_Extbase_Validation_Validator_GenericObjectValidator" but you would
have to manually register all Validators...
or is there actually a better/easier solution?
maybe someone can enlighten me :)
cheers
--
+---------------------------------+-----------------------------------+
| Thomas Allmer | http://www.delusionworld.com |
| E-mail: at at delusionworld.com | phone: +43 699 16217064 |
+---------------------------------+-----------------------------------+
More information about the TYPO3-project-typo3v4mvc
mailing list