private function processEdits($form_id, $form) { $fieldsPost = $this->input->post('fields'); // $i is not necessarily the field id (for new fields) foreach ($fieldsPost as $i => $fieldAttrs) { $field_id = $fieldAttrs['id']; $field = new Field(); $field->name = $fieldAttrs['name']; $field->description = $fieldAttrs['description']; $field->type = $fieldAttrs['type']; $field->order = $fieldAttrs['index']; $field->required = isset($fieldAttrs['required']); $options = new FieldOptions(); $options->setOptions($fieldAttrs['validation']); if ($field->type == "checkbox" || $field->type == "dropdown" || $field->type == "radio") { $options->setValueOptions($fieldAttrs['options']); } $field->options = $options; if (empty($field_id)) { $this->formsdb->addField($form_id, $field); } else { $this->formsdb->editField($form_id, $field_id, $field); } } }