[TYPO3-mvc] Default Values in Forms

Thomas Hempel thomas at typo3-unleashed.net
Sun Oct 17 12:23:56 CEST 2010


Hi,

I'm guessing around with the forms view helper for a few hours now. In 
my opinion I want to do a rather simple thing. I want to pre-fill some 
input fields when the form is rendered.

Well, it's a little bit more complex. I have a simple form with three 
select boxes. When the form is submitted, the page reloads, and a list 
of items shows up beneath the form and the form is pre-filled with the 
selectedboy items selected before. That works, no question here.

The user can select on of the items in the list and display a detail 
page. You see, this is a really common use case.

On the detail page, I have a back to overview link. Which brings the 
user back to the page with the form.

Now here comes the tricky part. When the user comes back, the form 
should be restated to the values it had before the user called the 
detail page. But that doesn't work! :-/

Of course the form-object is not in the request anymore. So what can I 
do? I tried some things but nothing worked for me. What I have tried:

Note: "formObject" is just a transient domain model object. It's not 
persistent in any way because the form is basically a search form.


1. Store form object in session and reassign it on load.

$this->view->assign('formObject', $formObject);

<form object={formObject}>....


This had no effect at all.



2. Use the value property of the select fields.

<f:form object={formObject}>

   <f:form.select property="myProperty1" options="{properties1}" 
value="{selectedProperty1}" />

   <f:form.select property="myProperty2" options="{properties2}" 
value="3" />

</f:form>


In this case, "value" for myProperty1 has no effect. But I can set it 
directly like for myProperty2 in the example above.


I really need some help here. Has anybody an idea how to do this? I 
mean, I can't believe nobody ever had this problem.



Thanks and best wishes,
Thomas




More information about the TYPO3-project-typo3v4mvc mailing list