Skip to content

Commit d4a1aa9

Browse files
committed
Add confirmation dialog before submitting a user note (#1281)
A native HTML dialog with checkboxes requires users to confirm their note is not a bug report, support question, code collaboration, or in a language other than English before submission.
1 parent 80d3119 commit d4a1aa9

1 file changed

Lines changed: 61 additions & 1 deletion

File tree

manual/add-note.php

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@
344344

345345
// Everything is in place, so we can display the form
346346
else {?>
347-
<form method="post" action="/manual/add-note.php">
347+
<form method="post" action="/manual/add-note.php" id="addnote-form">
348348
<p>
349349
<input type="hidden" name="sect" value="<?php echo clean($_POST['sect']); ?>">
350350
<input type="hidden" name="redirect" value="<?php echo clean($_POST['redirect']); ?>">
@@ -390,6 +390,66 @@
390390
<?php
391391
}
392392

393+
?>
394+
<dialog id="note-confirm-dialog">
395+
<form method="dialog">
396+
<h3>Before submitting your note</h3>
397+
<p>Please confirm that your note:</p>
398+
<ul>
399+
<li><label><input type="checkbox" required> Is <strong>not</strong> a bug report or feature request</label></li>
400+
<li><label><input type="checkbox" required> Is <strong>not</strong> a support question</label></li>
401+
<li><label><input type="checkbox" required> Is <strong>not</strong> a code collaboration or link to an external site</label></li>
402+
<li><label><input type="checkbox" required> Is written in <strong>English</strong></label></li>
403+
</ul>
404+
<p>
405+
<button type="submit" value="confirm">I confirm, submit my note</button>
406+
<button type="submit" value="cancel">Cancel</button>
407+
</p>
408+
</form>
409+
</dialog>
410+
<script>
411+
(function() {
412+
var form = document.getElementById('addnote-form');
413+
if (!form) return;
414+
415+
form.addEventListener('submit', function(e) {
416+
var action = e.submitter ? e.submitter.value : '';
417+
if (action !== 'Add Note') return;
418+
419+
var dialog = document.getElementById('note-confirm-dialog');
420+
if (!dialog || form.dataset.confirmed === '1') {
421+
form.dataset.confirmed = '';
422+
return;
423+
}
424+
425+
e.preventDefault();
426+
dialog.showModal();
427+
428+
dialog.querySelector('form').onsubmit = function(de) {
429+
var checkboxes = dialog.querySelectorAll('input[type="checkbox"]');
430+
for (var i = 0; i < checkboxes.length; i++) {
431+
if (!checkboxes[i].checked) {
432+
de.preventDefault();
433+
return;
434+
}
435+
}
436+
};
437+
438+
dialog.addEventListener('close', function handler() {
439+
dialog.removeEventListener('close', handler);
440+
if (dialog.returnValue === 'confirm') {
441+
form.dataset.confirmed = '1';
442+
e.submitter.click();
443+
}
444+
var checkboxes = dialog.querySelectorAll('input[type="checkbox"]');
445+
for (var i = 0; i < checkboxes.length; i++) {
446+
checkboxes[i].checked = false;
447+
}
448+
});
449+
});
450+
})();
451+
</script>
452+
<?php
393453
// Print out common footer
394454
site_footer();
395455
?>

0 commit comments

Comments
 (0)