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
In my controller my logic would look like this:
function submitform($data, $form) {
if(!empty($data['textfield'])){
//code for setting variables in the $form array
$form->setFields(?);
}
$submission = new User_Item();
$form->saveInto($submission);
$submission->write();
}
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?
function submitform($data, $form) {
if(!empty($data['textfield'])){
DB::query("INSERT INTO table VALUES (item=\'".$data['textfield']."\')");
} else {
DB::query("INSERT INTO table VALUES (item=\'".$data['dropdownbox']."\')");
}
}