Jump to content

jonathan_claeys

Members
  • Posts

    5
  • Joined

  • Last visited

Everything posted by jonathan_claeys

  1. The thing is that saving works perfect, but retrieving them from the database doesn't. It returns an empty array, and I would want to prefill my values ofc.
  2. 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('./'); } }
  3. Even with page->save() it doesn't get saved. I think it is because there is no place to actually save the value in the database, I dynamically try to add data and save it. But I don't know the right way to do it.
  4. <?php namespace ProcessWire; class ProcessCustomSettings extends Process { 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->page->data); $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(); foreach($this->input->post as $key => $value) { if(strpos($key, 'site_') === 0) { $this->page->data($key, $value); } } $this->message('Saved Settings'); $this->session->redirect('./'); } }
  5. So I'm trying to create a module. And I would like to store the general settings that the module holds. I made a page with the admin template and my own process module. Can I store my data on that same page with the module/admin template? Or is that not possible? I tried to add them to the page like: $this->page->$key = $value I also tried to add them to the page data like: $this->page->data($key, $value) But after redirecting the keys & values are gone. Kind regards, Jonathan
×
×
  • Create New...