Editing the contents of a Form class object

There's a few topics out there already similar to this (Such as here) but they never got an answer. I'm reviving this topic again because there is some clear interest in this but no instruction on how to do it so far

In my case I have two items on a form: a dropdownbox for selecting a pre-set item and a textfield for defining your own item if its not in the dropdownbox.

Since these two form fields are just different ways of defining the same thing, both form fields are for the exact same database field. The logic is, if you use the textfield then content of the textfield goes to the database and the dropdownbox content is ignored. if the textfield is empty, the content of the combobox goes to the database

Looking at the API, it looks like the setFields function is the only function capable of editing $form, but it's not clear how to use it properly. It takes a fieldset object containing an array of form objects, but giving $form a new fieldset object might completely replace everything rather than just overwrite what I want

SHORT VERSION: Is there a way to access and edit the contents of a Form class object?

---

If editing $form is impossible, perhaps it would be better if I just updated the database with my own code using the DB class. Agree/Disagree?

Alright since I really need to get this project done sooner than later, I'm going to take the silence as a 'no' and simply update the database myself with the DB class via my own MySQL queries. I know SQL inside and out so this is no problem for me

I am aware that according to the Silverstripe documentation, using the DB class to update the database yourself not recommended but right now it's the only way I know how to update the database in the specific way that I want it.

If anyone knows the proper way to customize database input then STOP ME NOW!

I have resolved my problem by using the DB class to update my database in my own way, rather than rely on the form data and Silverstripes functions for processing it.

If you are dealing with a form that's not consistent with your database and you have to get fancy with the form data, forget about editing the form array. It's too much trouble. Instead you may have to what I did: Do it yourself the good old fashioned way with the DB class and a little SQL knowledge using the data array

The dropdown field is technically saving just a single text object. It is not a country field, but for the sake of example; lets just pretend that it is.

The country specified in the dropdown field saves directly to the country column in the user table. Users may have only one country associated with them

While the dropdown field saves data to the user table, the contents of the dropdown field are retrieved from a separate table of countries: A country table filled with unique country names

I want users to be able to append to this table of countries so the dropdown box will list the countries that other users have chosen and/or any countries we forgot to list. This is done on the same form

So next to the dropdown you have a text field where the user can specify their own country if they cannot find the country they want in dropdown field.

If the user enters a new country in the text field, the contents of the text field is sent to the country column in the user table while the contents of the dropdown box is ignored completely. At the same time, the country is also added to the table of countries on record so that user-provided country will appear in the dropdown box for the next user.

NOTE: I stress again; it's not actually a country field. But exactly what it is, is not really important in this context so long as you understand the use case.

---

Anyway, thank you for your suggestion. It sounds like what I should be doing is instantiating a new object of class "user" and manipulating the individual properties of that class object (which will be easy enough to do)

The Write function will then do the SQL for me, is that what you mean?

EDIT: Answering my own question: Yes, that is what it does and that is what Willr meant.