How to add a "save" and "clear" button to forms?

For arguments sake I work in a “real estate” office. I want to create a database of several buildings, with records of all the residents in each building and all the contractors that work on each building. I would like to create simple forms where new residents or contractors can be add.

Native UI: These functions, save and clear are available in the form navigator at the bottom of the form. This can be made visible or invisible in the properties dialog box of the form control, Data Navigation bar. The icons on Linux look like a blue old-style floppy disk with a sideways triangle (save record) and a looping yellow arrow (undo data entry). Iterating to a new record also will automatically save data, and if the record is closed without saving the user will be prompted to save.
image description

Custom controls:
If a custom control is desired, it is not a trivial matter to get it to work properly because of the way that LO forms are updated. Updates are multi-step processes, with communication from controls to the form, flags and listeners. To start:

root_doc = ThisComponent
form_container = root_doc.DrawPage.Forms
main_form = form_container.getByIndex(0)

To update, iterate through all the controls on the form and commit changes, update the row; this will return an error if an object in the form does not have the commit method – tested ok with button and text boxes:

i = 0
  field = main_form.getByIndex(i)
  i = i + 1
Loop until i = (main_form.count - 1)


Or alternately to clear changes, cancel, reload, and go back to original record:

row_num = main_form.getRow()