Skip to content

Commit 98b7bd7

Browse files
committed
Add JSON validation during input in ACP field
1 parent 611cca7 commit 98b7bd7

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

adm/style/consentmanager_acp.html

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,12 @@ <h3>{{ lang('WARNING') }}</h3>
7777
<span><strong>{{ lang('EXAMPLE') ~ lang('COLON') }}</strong></span><br>
7878
<pre><samp class="error">{{ CONSENTMANAGER_INTEGRATIONS_EXAMPLE }}</samp></pre>
7979
</dt>
80-
<dd><textarea id="consentmanager_integrations" name="consentmanager_integrations" rows="14" cols="90">{{ CONSENTMANAGER_INTEGRATIONS|e('html') }}</textarea></dd>
80+
<dd>
81+
<div style="position: relative; display: inline-block;">
82+
<textarea id="consentmanager_integrations" name="consentmanager_integrations" rows="14" cols="90" style="padding-right: 7.5em; padding-bottom: 1.8em;">{{ CONSENTMANAGER_INTEGRATIONS|e('html') }}</textarea>
83+
<span id="consentmanager_integrations_warning" style="position: absolute; right: 0.8em; bottom: 0.8em; color: #bc2a4d; font-size: 0.85em; font-weight: bold; pointer-events: none; display: none;">{{ lang('ACP_CONSENTMANAGER_INVALID_JSON') }}</span>
84+
</div>
85+
</dd>
8186
</dl>
8287
</fieldset>
8388

@@ -96,4 +101,41 @@ <h3>{{ lang('WARNING') }}</h3>
96101
</fieldset>
97102
</form>
98103

104+
<script>
105+
document.addEventListener('DOMContentLoaded', function() {
106+
var textarea = document.getElementById('consentmanager_integrations');
107+
var warning = document.getElementById('consentmanager_integrations_warning');
108+
109+
if (!textarea || !warning)
110+
{
111+
return;
112+
}
113+
114+
var updateWarning = function() {
115+
var value = textarea.value.trim();
116+
var isValidArray = false;
117+
118+
if (value === '')
119+
{
120+
warning.style.display = 'none';
121+
return;
122+
}
123+
124+
try
125+
{
126+
isValidArray = Array.isArray(JSON.parse(value));
127+
}
128+
catch (error)
129+
{
130+
isValidArray = false;
131+
}
132+
133+
warning.style.display = isValidArray ? 'none' : 'block';
134+
};
135+
136+
textarea.addEventListener('input', updateWarning);
137+
updateWarning();
138+
});
139+
</script>
140+
99141
{% include 'overall_footer.html' %}

language/en/acp_consentmanager.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
'ACP_CONSENTMANAGER_REPROMPT_SUCCESS' => 'Consent version increased. Visitors will be asked to review their settings again.',
4141
'ACP_CONSENTMANAGER_INVALID_INTEGRATIONS' => 'The integrations field must contain a valid JSON array.',
4242
'ACP_CONSENTMANAGER_INVALID_INTEGRATION_ENTRY' => 'Integration entry %1$s is invalid. Each entry must include a safe id, supported category, and valid script source URL.',
43+
'ACP_CONSENTMANAGER_INVALID_JSON' => 'Invalid JSON',
4344
'CONSENTMANAGER_CATEGORY_NECESSARY' => 'Necessary',
4445
'CONSENTMANAGER_CATEGORY_ANALYTICS' => 'Analytics',
4546
'CONSENTMANAGER_CATEGORY_MARKETING' => 'Marketing',

0 commit comments

Comments
 (0)