HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Custom module settings validation

Is there a way to validate the values of settings (form fields) of a custom module when you hit save button? I am using the ConfigurationModule.



  • Options
    R_JR_J Ex-Fanboy Munich Admin
       public function settingsController_myPlugin_create($sender) {
           $sender->title(Gdn::translate('MyPlugin Settings'));
           $sender->description(Gdn::translate('MyPlugin Description'));
           $sender->Form = new Gdn_Form();
           $validation = new Gdn_Validation();
           if ($sender->Form->authenticatedPostBack()) {
               $formPostValues = $sender->Form->formValues();
               // Some examples using validations routiness.
               $validation->applyRule('Email', ['Required', 'Email']);
               $validation->applyRule('Password', 'Required');
               // Do custom validation here
               if ($formPostValues['Password'] === 'password') {
                   // Add a custom message.
                   $validation->addValidationResult('Password', 'Please don\'t use "password" as your password, Stupid!');
               // Insert all validation results to the form.
           $configurationModule = new ConfigurationModule($sender);
               // Your config here
  • Options

    Thank you so much

Sign In or Register to comment.