Jump to content

jonathan_claeys

Members
  • Posts

    5
  • Joined

  • Last visited

Posts posted by jonathan_claeys

  1. 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('./');
      }
    }

     

  2. <?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('./');
      }
    }

     

  3. 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...