|
344 | 344 |
|
345 | 345 | // Everything is in place, so we can display the form |
346 | 346 | else {?> |
347 | | -<form method="post" action="/manual/add-note.php"> |
| 347 | +<form method="post" action="/manual/add-note.php" id="addnote-form"> |
348 | 348 | <p> |
349 | 349 | <input type="hidden" name="sect" value="<?php echo clean($_POST['sect']); ?>"> |
350 | 350 | <input type="hidden" name="redirect" value="<?php echo clean($_POST['redirect']); ?>"> |
|
390 | 390 | <?php |
391 | 391 | } |
392 | 392 |
|
| 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 |
393 | 453 | // Print out common footer |
394 | 454 | site_footer(); |
395 | 455 | ?> |
0 commit comments