diff --git a/interface/web/dns/dns_dkim_edit.php b/interface/web/dns/dns_dkim_edit.php
index 367ed16185dacc3fba20e206204a52158794115a..520d3822816d738a94067c40e32a813a7747d435 100644
--- a/interface/web/dns/dns_dkim_edit.php
+++ b/interface/web/dns/dns_dkim_edit.php
@@ -70,15 +70,23 @@ class page_action extends tform_actions {
 		}
 
 		parent::onShowNew();
-	}
-
-	function onShowEnd() {
-		global $app, $conf;
 
-		$app->tpl->setVar("selector", str_replace('._domainkey', '', $this->dataRecord['name']), true);
-		$app->tpl->setVar("public_key", str_replace('v=DKIM1; t=s; p=', '', $this->dataRecord['data']), true);
+        $soa = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ? AND " . $app->tform->getAuthSQL('r'), $_GET['zone']);
+        $sql=$app->db->queryOneRecord("SELECT domain, dkim_public, dkim_selector, dkim FROM mail_domain WHERE domain = ? AND " . $app->tform->getAuthSQL('r'), substr_replace($soa['origin'],'',-1));
+		if(isset($sql['domain']) && $sql['domain'] != '') {
+			if($sql['dkim'] == 'y') {
+		        $public_key=str_replace(array('-----BEGIN PUBLIC KEY-----','-----END PUBLIC KEY-----',"\r","\n"),'',$sql['dkim_public']);
+				$app->tpl->setVar('public_key', $public_key, true);
+				$app->tpl->setVar('selector', $sql['dkim_selector'], true);
+			} else {
+			//TODO: show warning - use mail_domain for dkim and enabled dkim
+			}
+			$app->tpl->setVar('edit_disabled', 1);
+		} else {
+			$app->tpl->setVar('edit_disabled', 0);
+		}
+		$app->tpl->setVar('name', $soa['origin'], true);
 
-		parent::onShowEnd();
 	}
 
 	function onSubmit() {
@@ -109,7 +117,7 @@ class page_action extends tform_actions {
 		// add dkim-settings to the public-key in the txt-record
 		if (!empty($this->dataRecord['data'])) {
 			$this->dataRecord['data']='v=DKIM1; t=s; p='.$this->dataRecord['data'];
-			$this->dataRecord['name']=$this->dataRecord['selector'].'._domainkey';
+			$this->dataRecord['name']=$this->dataRecord['selector'].'._domainkey.'.$this->dataRecord['name'];
 //			$this->dataRecord['ttl']=60;
 		}
 		// Update the serial number  and timestamp of the RR record
diff --git a/interface/web/dns/dns_txt_edit.php b/interface/web/dns/dns_txt_edit.php
index f33600dafb7ba3ecc2e5d6ee960ce73a41617e22..7caa27d040c38955bd93d4fedc09b46df9091edd 100644
--- a/interface/web/dns/dns_txt_edit.php
+++ b/interface/web/dns/dns_txt_edit.php
@@ -57,9 +57,6 @@ class page_action extends dns_page_action {
 			if ('v=spf1' === mb_substr($this->dataRecord['data'], 0, 6)) {
 				header(sprintf('Location: dns_spf_edit.php?id=%d', $this->dataRecord['id']));
 				exit;
-                       } elseif ("v=DKIM1; t=s; p=" === mb_substr($this->dataRecord["data"], 0, 16)) {
-                               header(sprintf("Location: dns_dkim_edit.php?id=%d", $this->dataRecord["id"]));
-                               exit;
 			}
 		}
 	}
diff --git a/interface/web/dns/templates/dns_dkim_edit.htm b/interface/web/dns/templates/dns_dkim_edit.htm
index 2a6a5b4fe915b7252e1cfd0a6144ef1e8bb8aab4..2947a2ba8589d5f231451347ab859ed59b5e6488 100644
--- a/interface/web/dns/templates/dns_dkim_edit.htm
+++ b/interface/web/dns/templates/dns_dkim_edit.htm
@@ -26,6 +26,7 @@
 <input type="hidden" name="id" value="{tmpl_var name='id'}">
 <input type="hidden" name="zone" value="{tmpl_var name='zone'}" id="zone">
 <input type="hidden" name="type" value="{tmpl_var name='type'}">
+<input type="hidden" name="name" value="{tmpl_var name='name'}">
             
 <div class="clear"><div class="right">
 	<button class="btn btn-default formbutton-success" type="button" value="{tmpl_var name='btn_save_txt'}" data-submit-form="pageForm" data-form-action="dns/dns_dkim_edit.php">{tmpl_var name='btn_save_txt'}</button>