In the vain hope that the lack of answers to my question was only due to
pre-x-mas-stress, allow me to re-post it – I do believe my need is not too
uncommon...:
How can I get the form module to pre fill in a form when the user loads it the
first time?
- e.g. filling in the user profile info for a profile update form
- e.g. fill in a default from and to date in a reservation form
- and so on
Any pointers warmly appreciated!!!
Thanks!
-Will
On 17.12.2011, at 18:56, Will Scheidegger wrote:
> O.k., so I created a FormState and FormStepState object and filled in all the
> values I needed... but forgot to set the FormState object in the FormEngine.
> Unfortunately you cannot do this because there is no setter method for that
> and the attribute is private of course.
>
> Therefore again to all the Form Module gurus: What is the proper way to fill
> data into a form?
>
> Thanks!
> -will
>
> On 17.12.2011, at 11:59, Will Scheidegger wrote:
>
>> Dear Magnolians
>>
>> I'm trying to "upgrade" a custom profile update form to the STK PUR form.
>> However when you open the form all fields are empty. I would like to auto
>> fill in all of the form values by reading them from the current user – all
>> except the password. Of course these values should only be filled in once.
>> If the user removes the data from a field it should stay empty.
>>
>> Is there an easy way to achieve this?
>>
>> I've tried to write a custom form engine with the "handleTokenMissing()"
>> method below. It is called and goes through all fields, creates FormField
>> objects for every field and set's the value. However the form still does not
>> display the value set in this method... so I guess I'm still missing
>> something. Any ideas?
>>
>> @Override
>> protected View handleTokenMissing() throws RepositoryException {
>> // create a form state
>> FormState formState = FormStateUtil.createAndSetFormState();
>> // we need a step
>> FormStepState step = new FormStepState();
>> step.setParagraphUuid(this.getConfigurationNode().getUUID());
>> formState.addStep(step);
>>
>> if (SecurityUtil.isAuthenticated()) {
>> User user = MgnlContext.getUser();
>> // auto fill in the values from the user
>> if (this.getConfigurationNode().hasContent("fieldsets")) {
>> Iterator itFieldsets =
>> this.getConfigurationNode().getContent("fieldsets").getChildren().iterator();
>> while (itFieldsets.hasNext()) {
>> Content fieldset = (Content) itFieldsets.next();
>> if (fieldset.hasContent("fields")) {
>> Iterator iterator =
>> fieldset.getContent("fields").getChildren().iterator();
>> while (iterator.hasNext()) {
>> final Content node = (Content) iterator.next();
>> if (node.hasNodeData("controlName")) {
>> final String controlName =
>> node.getNodeData("controlName").getString();
>> FormField field = new FormField();
>> field.setName(controlName);
>> if (controlName.equals("password") ||
>> controlName.equals("passwordConfirmation")) {
>> // skip this!
>> } else {
>> try {
>>
>> field.setValue(BeanUtils.getProperty(user, controlName));
>> } catch (Exception ex) {
>> if (user.getProperty(controlName) !=
>> null) {
>>
>> field.setValue(user.getProperty(controlName));
>> }
>> }
>> }
>> step.add(field);
>> }
>> }
>> }
>> }
>> }
>> }
>> View view = getFormView(step);
>> return view;
>> }
>>
>>
>> Thanks!
>> -will
>>
>>
>>
>> ----------------------------------------------------------------
>> For list details, see
>> http://www.magnolia-cms.com/community/mailing-lists.html
>> Alternatively, use our forums: http://forum.magnolia-cms.com/
>> To unsubscribe, E-mail to: <[email protected]>
>> ----------------------------------------------------------------
>
>
>
> ----------------------------------------------------------------
> For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
> Alternatively, use our forums: http://forum.magnolia-cms.com/
> To unsubscribe, E-mail to: <[email protected]>
> ----------------------------------------------------------------
----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------