coax / hmailserver-webadmin

hMailServer PHPWebAdmin redesign project
https://www.hmailserver.com
79 stars 19 forks source link

Forwarding address field allows multiple recipients #40

Closed RvdHout closed 3 weeks ago

RvdHout commented 3 years ago

Forwarding email address field under account accepts: test1@test.com; test2@test.com (this is invalid in hMailServer)

hMailServer accepts only a single email address under forwarding thru an account, if you like to forward it to multiple recipients you are forced to use a distribution list

coax commented 3 years ago

That field is not required by default before saving, therefore is not checked for validity (eg. e-mail address regex). Not possible to check/validate fields which are not required.

RvdHout commented 3 years ago

Sure you can, just be creative

// form validation
$.fn.validation = function() {

...

    if ($('#forwardaddress').length) {
        $('#forwardaddress').toggleClass( 'req', $('#forwardenabled').is(':checked') );
    }
...
}
coax commented 3 years ago

I understand it can be done this way (custom code for just one field) but that is not a good programming practice.

I will deal with this on a global level in the next release.

RvdHout commented 3 years ago

Just to give you a idea, when dealt with on a global level it is even better

https://github.com/coax/hmailserver-webadmin/pull/41/commits/66d63645ae6f379763844751b3bd0f5a76a7926c

As a global solution you perhaps could give those "conditional" fields some data attribute, data-depends-on="control" and then add the 'req' class with jquery as required (similar to the above)

$.fn.hasAttr = function(name) {  
   return this.attr(name) !== undefined;
};

// form validation
$.fn.validation = function() {

...

    // conditional checks
    $('.form input, .form textarea').each(function() {
        if ($(this).hasAttr('data-depends-on')){ 
            var control = "#" + $(this).attr('data-depends-on');
            $(this).toggleClass( 'req', $(control).is(':checked') );
        }
    });
...
}
coax commented 3 weeks ago

Added in v1.6