Cold_Class
Cold_Class

Reputation: 3484

Properties that were not listed in fluid-form overwritten after submit

In my extbase 6.2 extension (built with extension builder) I have:

In my form I simply want to edit the expertises, but every time I hit submit my lawyer's properties are emptied except for the expertises - those work, even their values are correct.
When I debug the object in fluid the lawyer is there and everything is correct.
This is the only place in my fluid form where I wrote the word "lawyer".

<f:for each="{appointment.lawyer.expertises}" as="expertise" iteration="i">  
   <f:form.checkbox property="lawyer.expertises.{i.index}.checked" value="1"/>
   <f:for each="{expertise.subExpertises}" as="subExpertise" iteration="j">
      <f:form.checkbox property="lawyer.expertises.{i.index}.subExpertises.{j.index}.checked" value="1"/>
   </f:for>
</f:for>

Usually my properties of appointment don't get overwritten just because I don't write a form input-field for them.
So why are the properties of appointment.lawyer overwritten and how can I keep this from happening?

Unfortunately I have no idea what TYPO3 is doing in order to build an object from my form so any hints on that would be appreciated too :)

Upvotes: 1

Views: 407

Answers (1)

Dimitri Lavren&#252;k
Dimitri Lavren&#252;k

Reputation: 4879

It is not that easy to edit the properties of related elements.

What TYPO3 does in your case is that the original related lawyer record (and also the original expertises) is detached from the appointment object and a new one is created instead, that is why you think the other properties are emptied. You will also see that, if you look up your elements in the list view, there will be more and more each time you save it. The reason is that the form is not automatically generated with the lawyer's and expertises's uids so TYPO3 thinks that these are new objects.

There is one solution I know (if someone knows a better one, please share) But you need to read the whole description: You have to manually add the uid field in your form for every related object. Assuming that your form has name="appointment"

<f:form.hidden name="appointment[lawyer][__identity]" value="{appointment.lawyer.uid}" />

<f:form.hidden name="appointment[lawyer][expertises][{i.index}][__identity]" value="{expertise.uid}"/>

You will also have to do it for the subproperties.

Important! That way the user can also manipulate the ids and modify the objects that he is not supposed to have access to, so you have to check the relations before saving. For that you can use the _getCleanProperty('xx') method of a domain object to get the original data of it.

if ($appointment->getLawyer()->getUid() != $appointment->_getCleanProperty('lawyer')->getUid()) {
    die('error');
}

You need to check all the relations that can be manipulated that way of course.

Upvotes: 4

Related Questions