/** * It is used to save form data * * It fetches the form data from application parameters * It saves the form data to database * * @return $is_saved boolean indicates if the data was successfully saved */ private function SaveFormData() { /** The application parameters are fetched */ $parameters = $this->GetConfig("general", "parameters"); /** The data to be saved to database */ $form_data = array(); /** The submited form data is fetched */ foreach ($parameters['form'] as $key => $value) { /** If the form mode is add and the field */ if ($parameters['mode'] == 'add' && strpos($key, "_id") !== false) { continue; } /** Only textarea and input fields are saved */ if (strpos($key, "textarea") === false && strpos($key, "input") === false) { continue; } else { $database_field_name = str_replace("textarea_", "", $key); $database_field_name = str_replace("input_", "", $database_field_name); $form_data[$database_field_name] = $value; } } /** The data to be saved is filtered */ $form_data = $this->FilterSaveData($form_data); /** The application configuration is fetched */ $configuration = $this->GetConfigurationObject(); /** The parameters for the data object */ $meta_information = array("configuration" => $configuration, "key_field" => "id", "data_type" => $this->data['data_type']); /** Mysqldataobject is created */ $data_object = new MysqlDataObject($meta_information); /** The data is set to the mysqldataobject */ $data_object->SetData($form_data); /** If the form is in add mode, then the database is checked for existing record */ if ($parameters['mode'] == 'add') { /** If the record already exists in database, then the function returns -1 */ if ($data_object->RecordExists()) { $is_saved = -1; return $is_saved; } } /** The Mysqldataobject is set to read/write */ $data_object->SetReadonly(false); /** The form data is saved to database */ $is_saved = $data_object->Save() ? true : false; return $is_saved; }