How to get data from a writer form into a field variable?

I want to create a form-driven writer document.

For example, I want a document that looks like this:

My favorite toy is: [ball].
My favorite colour is [blue].
I would like a blue ball for my birthday.

Where the fields marked with [brackets] are form fields and the last sentence picks up “blue” and “ball” from the form.

There are lots of guides to using forms to drive databases but I can’t find one that shows how to use them for a document.

Any pointers would be appreciated.

favourites.odt

Insert → Fields → Other → Variables → Set a variable, pick a name, value and Format (text).

Later you can insert the variable again with “Display variable”. If you double click on the variable where it is set, you can change the value.

Yes. And no… That is using fields. They are too easy for a user to delete. I want to use a form, where there is a form design drawn with a boxes to enter text (or buttons to set other things). I want to capture data from the form then use it to drive the output. I guess that somehow i need to capture the data from the form into a macro but I can find no examples of this.

You could search “OpenOffice Writer form macro”.