From 849a4579e99e292576b27a0dbca92d94e2b90c03 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 30 Aug 2026 22:04:31 -0400 Subject: [PATCH] remove the school reference --- app/Controllers/View/ParentController.php | 16 +-- app/Views/parent/register_student.php | 2 +- app/Views/partials/student_form.php | 130 +++++------------- public/assets/js/validate_student.js | 49 ++----- .../templates/student-form-template.html | 22 ++- 5 files changed, 66 insertions(+), 153 deletions(-) diff --git a/app/Controllers/View/ParentController.php b/app/Controllers/View/ParentController.php index 2db3087..0bb8744 100644 --- a/app/Controllers/View/ParentController.php +++ b/app/Controllers/View/ParentController.php @@ -2140,21 +2140,9 @@ class ParentController extends BaseController // Loop through students foreach ($incomingFirstNames as $idx => $firstName) { if (!empty($firstName)) { - // ✅ 7. Extract is_new flag (convert to boolean) $lastYearKey = 'last_year_' . $idx; - $lastYearVal = strtolower(trim($post[$lastYearKey] ?? '')); - - $isNew = match ($lastYearVal) { - 'yes' => false, // was with us last year => not new - 'no' => true, // was not with us => new student - default => null // missing or invalid - }; - - if (!isset($isNew)) { - return redirect()->back()->withInput()->with('error', "Please select if student #" . ($idx + 1) . " was with us last year."); - } - - // ✅ 8. Pass $isNew to the student save function + $lastYearVal = strtolower(trim($post[$lastYearKey] ?? 'no')); + $isNew = $lastYearVal !== 'yes'; $result = $this->validateAndSaveOrUpdateStudent($idx, $parentId, $this->semester, $this->schoolYear, $schoolIdService, $isNew, null); if ($result) { diff --git a/app/Views/parent/register_student.php b/app/Views/parent/register_student.php index 0b6df03..6a1b8a5 100644 --- a/app/Views/parent/register_student.php +++ b/app/Views/parent/register_student.php @@ -423,6 +423,6 @@ $closeAtFmt12 = $closeAt->format('m-d-Y g:i A T'); // e.g., 10-01-2025 12:00 AM - + endSection() ?> diff --git a/app/Views/partials/student_form.php b/app/Views/partials/student_form.php index 664e018..bd8ef06 100644 --- a/app/Views/partials/student_form.php +++ b/app/Views/partials/student_form.php @@ -1,22 +1,25 @@
+ 'Not enrolled in public school', + 'KG' => 'Pre-K / Kindergarten', + '1' => 'Grade 1', + '2' => 'Grade 2', + '3' => 'Grade 3', + '4' => 'Grade 4', + '5' => 'Grade 5', + '6' => 'Grade 6', + '7' => 'Grade 7', + '8' => 'Grade 8', + '9' => 'Grade 9', + '10' => 'Grade 10', + '11' => 'Grade 11', + '12' => 'Grade 12', + ]; + ?>
Student Information
-
- - -
-
- - -
-
- - -
-
-
+
@@ -50,12 +53,14 @@ Student must be between 5 and 18 years old.
- +
@@ -231,46 +236,6 @@ value: "12", text: "Grade 12" } - ], - alrahma: [{ - value: "KG", - text: "Pre-K / Kindergarten" - }, - { - value: "1", - text: "Grade 1" - }, { - value: "2", - text: "Grade 2" - }, - { - value: "3", - text: "Grade 3" - }, { - value: "4", - text: "Grade 4" - }, - { - value: "5", - text: "Grade 5" - }, { - value: "6", - text: "Grade 6" - }, - { - value: "7", - text: "Grade 7" - }, { - value: "8", - text: "Grade 8" - }, - { - value: "9", - text: "Grade 9" - }, { - value: "10", - text: "Youth" - } ] }; @@ -278,8 +243,9 @@ if (!gradeSelect || !gradeLabel) return; gradeSelect.innerHTML = ''; gradeSelect.value = ''; - gradeSelect.disabled = true; // keep disabled until a radio is chosen - gradeLabel.innerHTML = 'Last Year Grade *'; + gradeSelect.disabled = false; + gradeLabel.innerHTML = 'Public School Last Year Grade *'; + populateSelect(gradeSelect, gradeOptions.public); } function populateSelect(gradeSelect, options) { @@ -292,50 +258,22 @@ }); } - function updateGradeOptions(studentForm, type) { + function updateGradeOptions(studentForm) { const gradeSelect = studentForm.querySelector('.grade-select'); const gradeLabel = studentForm.querySelector('.grade-label'); if (!gradeSelect || !gradeLabel) return; - gradeSelect.disabled = false; // enable now that a choice was made + gradeSelect.disabled = false; gradeSelect.value = ''; // clear any stale selection - - if (type === 'yes') { - gradeLabel.innerHTML = 'Al Rahma School Last Year Grade *'; - populateSelect(gradeSelect, gradeOptions.alrahma); - } else if (type === 'no') { - gradeLabel.innerHTML = 'Public School Last Year Grade *'; - populateSelect(gradeSelect, gradeOptions.public); - } else { - resetGradeSelect(gradeSelect, gradeLabel); - } + gradeLabel.innerHTML = 'Public School Last Year Grade *'; + populateSelect(gradeSelect, gradeOptions.public); } - // Event: when a radio is chosen, update this form's select - document.addEventListener('change', function(e) { - if (e.target.matches('input[type="radio"][data-base-name="last_year"]')) { - const form = e.target.closest('.student-form'); - if (form && e.target.checked) { - updateGradeOptions(form, e.target.value); - } - } - }); - - // On load: enforce disabled unless a radio is already checked (server repopulation) + // On load: ensure grade dropdown is populated. (function initStudentForms() { const forms = document.querySelectorAll('.student-form'); forms.forEach(form => { - const gradeSelect = form.querySelector('.grade-select'); - const gradeLabel = form.querySelector('.grade-label'); - - // Start disabled (HTML already has disabled, but enforce from JS too) - resetGradeSelect(gradeSelect, gradeLabel); - - // If a radio is already checked (e.g., after validation error), enable/populate accordingly - const checked = form.querySelector('input[type="radio"][data-base-name="last_year"]:checked'); - if (checked) { - updateGradeOptions(form, checked.value); - } + updateGradeOptions(form); }); })(); - \ No newline at end of file + diff --git a/public/assets/js/validate_student.js b/public/assets/js/validate_student.js index 1a31a5c..b4d8782 100644 --- a/public/assets/js/validate_student.js +++ b/public/assets/js/validate_student.js @@ -148,6 +148,10 @@ import { validateAgeLive } from './age_validation.js'; input.name = base + '[' + index + ']'; } }); + formEl.querySelectorAll('input[data-last-year-default]').forEach(function (input) { + input.name = 'last_year_' + index; + input.value = 'no'; + }); }); } @@ -249,18 +253,14 @@ import { validateAgeLive } from './age_validation.js'; } function setDefaultsForNewStudentForm(formEl) { - // Do NOT preselect any radio - formEl.querySelectorAll('input[type="radio"][data-base-name="last_year"]').forEach(function (r) { - r.checked = false; - }); - - // Keep grade select disabled until a choice is made var gradeSelect = formEl.querySelector('.grade-select'); var gradeLabel = formEl.querySelector('.grade-label'); if (gradeSelect && gradeLabel) { - gradeSelect.innerHTML = ''; - gradeSelect.disabled = true; - gradeLabel.innerHTML = 'Last Year Grade *'; + gradeSelect.disabled = false; + gradeLabel.innerHTML = 'Public School Last Year Grade *'; + if (typeof window.updateGradeOptions === 'function') { + try { window.updateGradeOptions(formEl); } catch (ex) { warn('updateGradeOptions default error', ex); } + } } } @@ -411,22 +411,6 @@ function addEmergencyForm() { }); } - // Enable grade select only after the last_year radio is chosen - container.addEventListener('change', function (e) { - var target = e.target; - if (target && target.matches('input[type="radio"][data-base-name="last_year"]') && target.checked) { - var studentForm = target.closest('.student-form'); - if (!studentForm) return; - - if (typeof window.updateGradeOptions === 'function') { - try { window.updateGradeOptions(studentForm, target.value); } catch (ex) { warn('updateGradeOptions error', ex); } - } else { - var gradeSelect = studentForm.querySelector('.grade-select'); - if (gradeSelect) gradeSelect.disabled = false; - } - } - }); - // ---- Submit & Validation ---- form.addEventListener('submit', function (e) { try { @@ -489,12 +473,6 @@ function addEmergencyForm() { allValid = allValid && ok; }); - // Radio groups per student (e.g., last_year) - form.querySelectorAll('.student-form').forEach((sf) => { - const radiosOk = validateRadioGroup(sf, 'last_year'); - allValid = allValid && radiosOk; - }); - // ---- Validate allergies & medical conditions for each student ---- let groupOk = true; form.querySelectorAll('.student-form').forEach(function (block, idx) { @@ -593,11 +571,10 @@ function addEmergencyForm() { wireChecklistLiveValidation(form); updateButtonStates(); - // If server repopulated radios, reflect in grade select + // If server repopulated radios, reflect in grade select. container.querySelectorAll('.student-form').forEach(function (sf) { - var checked = sf.querySelector('input[type="radio"][data-base-name="last_year"]:checked'); - if (checked && typeof window.updateGradeOptions === 'function') { - try { window.updateGradeOptions(sf, checked.value); } catch (ex) { warn('updateGradeOptions init error', ex); } + if (typeof window.updateGradeOptions === 'function') { + try { window.updateGradeOptions(sf); } catch (ex) { warn('updateGradeOptions init error', ex); } } }); @@ -609,4 +586,4 @@ function addEmergencyForm() { allowEmergency: allowEmergency }); }); -})(); \ No newline at end of file +})(); diff --git a/public/assets/templates/student-form-template.html b/public/assets/templates/student-form-template.html index 8afd58e..153996e 100644 --- a/public/assets/templates/student-form-template.html +++ b/public/assets/templates/student-form-template.html @@ -3,11 +3,7 @@

Student-# Information

-
-
- Yes - No -
+
@@ -28,6 +24,20 @@
@@ -44,4 +54,4 @@
- \ No newline at end of file +