Ok small update, I am now able to save to data into the module config settings. But I can not retrieve them afterwards to prefill fields. The var_dump just returns an empty array. Am I doing something wrong to retrieve the config data? When I check the database, the values are actually saved in the data field, so I'm sure it's not empty.
<?php namespace ProcessWire;
class ProcessCustomSettings extends Process implements Module, ConfigurableModule {
public static function getModuleinfo() {
return [
'title' => 'Processwire Custom Settings',
'summary' => 'Create your own custom settings.',
'author' => 'Jonathan Claeys',
'version' => '1.0.1',
'page' => [
'name' => 'settings',
'title' => 'Settings',
],
];
}
public function ___execute() {
var_dump($this->modules->getConfig($this));
$form = $this->modules->get('InputfieldForm');
$field = $this->modules->get('InputfieldText');
$field->name = 'site_name';
$field->label = 'Sitename';
$form->add($field);
$fieldset = $this->modules->get('InputfieldFieldset');
$fieldset->name = 'site_contact_information_fieldset';
$fieldset->label = 'Contact information';
$fieldset->collapsed = true;
$field = $this->modules->get('InputfieldText');
$field->name = 'site_email';
$field->label = 'E-mail';
$fieldset->add($field);
$field = $this->modules->get('InputfieldText');
$field->name = 'site_telephone';
$field->label = 'Telephone';
$fieldset->add($field);
$field = $this->modules->get('InputfieldText');
$field->name = 'site_fax';
$field->label = 'Fax';
$fieldset->add($field);
$form->add($fieldset);
$fieldset = $this->modules->get('InputfieldFieldset');
$fieldset->name = 'site_address_information_fieldset';
$fieldset->label = 'Address information';
$fieldset->collapsed = true;
$field = $this->modules->get('InputfieldText');
$field->name = 'site_address';
$field->label = 'Address';
$fieldset->add($field);
$field = $this->modules->get('InputfieldText');
$field->name = 'site_postal_code';
$field->label = 'Postal code';
$field->columnWidth = 34;
$fieldset->add($field);
$field = $this->modules->get('InputfieldText');
$field->name = 'site_city';
$field->label = 'City';
$field->columnWidth = 66;
$fieldset->add($field);
$form->add($fieldset);
$button = $this->modules->get('InputfieldSubmit');
$button->value = 'Save';
$form->add($button);
$form->action = './savecustomsettings';
return $form->render();
}
public function ___executeSaveCustomSettings() {
if(!$this->input->post('submit')) throw new Wire404Exception();
$data = array();
foreach($this->input->post as $key => $value) {
if(strpos($key, 'site_') === 0) {
$data[$key] = $value;
}
}
$this->modules->saveConfig($this, $data);
$this->message('Saved Settings');
$this->session->redirect('./');
}
}