From 416c5781dea9eac60f0efd9653a353ae426a55be Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Thu, 18 Sep 2025 11:06:21 +0000 Subject: [PATCH] checkboxes --- assets/js/main.js | 63 ++++++++++++-- index.php | 206 ++++++++++++++++++++++++++++++++++++++-------- submit_vote.php | 7 +- 3 files changed, 230 insertions(+), 46 deletions(-) diff --git a/assets/js/main.js b/assets/js/main.js index fb33baa..3d1134e 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -1,13 +1,49 @@ document.addEventListener('DOMContentLoaded', function () { - const beautifulForm = document.getElementById('beautiful-form'); - const funnyForm = document.getElementById('funny-form'); + const beautyVotes = []; + const funnyVotes = []; + + const beautyInput = document.getElementById('website_number_beauty'); + const funnyInput = document.getElementById('website_number_funny'); const toastLiveExample = document.getElementById('liveToast'); const toast = new bootstrap.Toast(toastLiveExample); + document.querySelectorAll('.form-check-input[data-category]').forEach(checkbox => { + checkbox.addEventListener('change', function() { + const category = this.dataset.category; + const websiteNumber = this.dataset.websiteNumber; + const votes = (category === 'beauty') ? beautyVotes : funnyVotes; + const input = (category === 'beauty') ? beautyInput : funnyInput; + + if (this.checked) { + if (votes.length >= 3) { + this.checked = false; + alert('You can only select up to 3 websites per category.'); + return; + } + votes.push(websiteNumber); + } else { + const index = votes.indexOf(websiteNumber); + if (index > -1) { + votes.splice(index, 1); + } + } + + votes.sort((a, b) => a - b); + input.value = votes.join(', '); + }); + }); + const handleFormSubmit = (form, event) => { event.preventDefault(); const formData = new FormData(form); const data = Object.fromEntries(formData.entries()); + const votes = (data.category === 'beauty') ? beautyVotes : funnyVotes; + + // Add the individual vote numbers to the data object for the backend + data.website_number_1 = votes[0] || ''; + data.website_number_2 = votes[1] || ''; + data.website_number_3 = votes[2] || ''; + delete data.website_numbers; // remove the comma-separated string fetch('submit_vote.php', { method: 'POST', @@ -17,12 +53,23 @@ document.addEventListener('DOMContentLoaded', function () { body: JSON.stringify(data), }) .then(response => response.json()) - .then(data => { - if (data.success) { + .then(result => { + if (result.success) { toast.show(); form.reset(); + + // Clear the votes and checkboxes for the submitted category + if (data.category === 'beauty') { + beautyVotes.length = 0; + document.querySelectorAll('input[data-category="beauty"]').forEach(cb => cb.checked = false); + beautyInput.value = ''; + } else { + funnyVotes.length = 0; + document.querySelectorAll('input[data-category="funny"]').forEach(cb => cb.checked = false); + funnyInput.value = ''; + } } else { - alert('Error: ' + data.error); + alert('Error: ' + result.error); } }) .catch((error) => { @@ -31,6 +78,6 @@ document.addEventListener('DOMContentLoaded', function () { }); }; - beautifulForm.addEventListener('submit', (event) => handleFormSubmit(beautifulForm, event)); - funnyForm.addEventListener('submit', (event) => handleFormSubmit(funnyForm, event)); -}); + document.getElementById('beautiful-form').addEventListener('submit', (event) => handleFormSubmit(event.target, event)); + document.getElementById('funny-form').addEventListener('submit', (event) => handleFormSubmit(event.target, event)); +}); \ No newline at end of file diff --git a/index.php b/index.php index 6bb97ab..8eab1fe 100644 --- a/index.php +++ b/index.php @@ -23,30 +23,174 @@

Websites for Voting

    -
  1. https://counterwars.dev.flatlogic.app
  2. -
  3. https://justvibing.dev.flatlogic.app
  4. -
  5. https://flower-shop.dev.flatlogic.app
  6. -
  7. https://pizzaslicer.dev.flatlogic.app
  8. -
  9. https://vm-34156.dev.flatlogic.app
  10. -
  11. https://digital-museum.dev.flatlogic.app
  12. -
  13. https://sell-product.dev.flatlogic.app
  14. -
  15. https://my-portfolio.dev.flatlogic.app
  16. -
  17. https://project-manager.dev.flatlogic.app
  18. -
  19. https://codeninja.dev.flatlogic.app
  20. -
  21. https://vibecoder-lab.dev.flatlogic.app
  22. -
  23. https://check-grammar.dev.flatlogic.app
  24. -
  25. https://magicv.dev.flatlogic.app
  26. -
  27. https://personal-landing-page.dev.flatlogic.app
  28. -
  29. https://fern.dev.flatlogic.app
  30. -
  31. https://todo.dev.flatlogic.app
  32. -
  33. https://hirebridge.dev.flatlogic.app
  34. -
  35. https://ice-cream-shop.dev.flatlogic.app
  36. -
  37. https://snake.dev.flatlogic.app
  38. -
  39. https://mindful-garden.dev.flatlogic.app
  40. -
  41. https://vm-34034.dev.flatlogic.app
  42. -
  43. https://memory-flip.dev.flatlogic.app
  44. -
  45. https://nestboard.dev.flatlogic.app
  46. -
  47. https://test-web.dev.flatlogic.app
  48. +
  49. + https://counterwars.dev.flatlogic.app +
    + + +
    +
  50. +
  51. + https://justvibing.dev.flatlogic.app +
    + + +
    +
  52. +
  53. + https://flower-shop.dev.flatlogic.app +
    + + +
    +
  54. +
  55. + https://pizzaslicer.dev.flatlogic.app +
    + + +
    +
  56. +
  57. + https://vm-34156.dev.flatlogic.app +
    + + +
    +
  58. +
  59. + https://digital-museum.dev.flatlogic.app +
    + + +
    +
  60. +
  61. + https://sell-product.dev.flatlogic.app +
    + + +
    +
  62. +
  63. + https://my-portfolio.dev.flatlogic.app +
    + + +
    +
  64. +
  65. + https://project-manager.dev.flatlogic.app +
    + + +
    +
  66. +
  67. + https://codeninja.dev.flatlogic.app +
    + + +
    +
  68. +
  69. + https://vibecoder-lab.dev.flatlogic.app +
    + + +
    +
  70. +
  71. + https://check-grammar.dev.flatlogic.app +
    + + +
    +
  72. +
  73. + https://magicv.dev.flatlogic.app +
    + + +
    +
  74. +
  75. + https://personal-landing-page.dev.flatlogic.app +
    + + +
    +
  76. +
  77. + https://fern.dev.flatlogic.app +
    + + +
    +
  78. +
  79. + https://todo.dev.flatlogic.app +
    + + +
    +
  80. +
  81. + https://hirebridge.dev.flatlogic.app +
    + + +
    +
  82. +
  83. + https://ice-cream-shop.dev.flatlogic.app +
    + + +
    +
  84. +
  85. + https://snake.dev.flatlogic.app +
    + + +
    +
  86. +
  87. + https://mindful-garden.dev.flatlogic.app +
    + + +
    +
  88. +
  89. + https://vm-34034.dev.flatlogic.app +
    + + +
    +
  90. +
  91. + https://memory-flip.dev.flatlogic.app +
    + + +
    +
  92. +
  93. + https://nestboard.dev.flatlogic.app +
    + + +
    +
  94. +
  95. + https://test-web.dev.flatlogic.app +
    + + +
    +
@@ -64,10 +208,8 @@
- - - - + +
@@ -86,10 +228,8 @@
- - - - + +
@@ -118,6 +258,6 @@ - + \ No newline at end of file diff --git a/submit_vote.php b/submit_vote.php index b7a6edb..7f38821 100644 --- a/submit_vote.php +++ b/submit_vote.php @@ -29,11 +29,8 @@ if (!$data) { $voterName = $data['voter_name'] ?? ''; $category = $data['category'] ?? ''; -$website_numbers = [ - $data['website_number_1'] ?? 0, - $data['website_number_2'] ?? 0, - $data['website_number_3'] ?? 0, -]; +$website_numbers_str = $data['website_numbers'] ?? ''; +$website_numbers = !empty($website_numbers_str) ? explode(',', $website_numbers_str) : []; if (empty($voterName) || empty($category) || !in_array($category, ['beauty', 'funny'])) { echo json_encode(['success' => false, 'error' => 'Invalid data provided.']);