dracoblue.net

Pre-Populating Formfields in Agavi

The AgaviFromPopulationFilter is handy to re-fill a form after validation failed and the user needs to check the values again (without refilling them by hand again).

But the FormPopulationFilter (FPF) is also capable of pre-filling forms.

Just get into your view and add the following:

if ([strong]'read'[/strong] == $this->getContext()->getRequest()->getMethod()) {
        $this->getContext()->getRequest()->setAttribute('[strong]populate[/strong]',
            new AgaviParameterHolder(
                array(
                    'name' => 'Test Entry',
                    [strong]'description'[/strong] => 'This is a short description'
                )
            ), 'org.agavi.filter.FormPopulationFilter'
        );
    }

and your Formfields 'name' and 'description' will be prefilled.

I added the check for 'read' method, since you don't want to auto populate in the case you submitted the data.

The template looks tidy now:

<input type="text" name="name" />
<textarea name="[strong]description[/strong]"></textarea>

Thanks to

veikko and saracen.

In agavi, open source, php by
@ 17 Feb 2009, Comments at Reddit & Hackernews

Give something back

Were my blog posts useful to you? If you want to give back, support one of these charities, too!

Report hate in social media Campact e.V. With our technology and your help, we protect the oceans from plastic waste. Gesellschaft fur Freiheitsrechte e. V. The civil eye in the mediterranean

Recent Dev-Articles

Read recently

Recent Files

About