diff --git a/layouts/v7/modules/Contacts/resources/Detail.js b/layouts/v7/modules/Contacts/resources/Detail.js
index 3d7b168fe00eb8e7d029efcf56f295e9ec80b572..9fc987c721fcf3c396041c50c02eb91853c68272 100644
--- a/layouts/v7/modules/Contacts/resources/Detail.js
+++ b/layouts/v7/modules/Contacts/resources/Detail.js
@@ -22,8 +22,8 @@ Vtiger_Detail_Js("Contacts_Detail_Js", {}, {
 	checkForPortalUser: function (form) {
 		var element = jQuery('[name="portal"]', form);
 		var response = element.is(':checked');
-		var primaryEmailField = jQuery('[name="email"]');
-		var primaryEmailValue = primaryEmailField.val();
+		var primaryEmailField = jQuery('[data-name="email"]');
+		var primaryEmailValue = primaryEmailField["0"].attributes["data-value"].value;
 		if (response) {
 			if (primaryEmailField.length == 0) {
 				app.helper.showErrorNotification({message: app.vtranslate('JS_PRIMARY_EMAIL_FIELD_DOES_NOT_EXISTS')});
diff --git a/layouts/v7/modules/Vtiger/AdvanceFilter.tpl b/layouts/v7/modules/Vtiger/AdvanceFilter.tpl
index 2cc3642b8641ae0e92ea4042c8fa1190f20a1f39..2895431a26922928321c28a39a288a8033658394 100644
--- a/layouts/v7/modules/Vtiger/AdvanceFilter.tpl
+++ b/layouts/v7/modules/Vtiger/AdvanceFilter.tpl
@@ -28,7 +28,7 @@
 	{foreach key=ADVANCE_FILTER_OPTION_KEY item=ADVANCE_FILTER_OPTION from=$ADVANCED_FILTER_OPTIONS}
 		{$ADVANCED_FILTER_OPTIONS[$ADVANCE_FILTER_OPTION_KEY] = vtranslate($ADVANCE_FILTER_OPTION, $MODULE)}
 	{/foreach}
-	<input type=hidden name="advanceFilterOptions" data-value='{ZEND_JSON::encode($ADVANCED_FILTER_OPTIONS)}' />
+	<input type=hidden name="advanceFilterOptions" data-value='{Vtiger_Util_Helper::toSafeHTML(ZEND_JSON::encode($ADVANCED_FILTER_OPTIONS))}' />
     <div class="allConditionContainer conditionGroup contentsBackground" style="padding-bottom:15px;">
         <div class="header">
 			<span><strong>{vtranslate('LBL_ALL_CONDITIONS',$MODULE)}</strong></span>
@@ -83,4 +83,4 @@
 		</div>
 	</div>
 </div>
-{/strip}
\ No newline at end of file
+{/strip}