remove the school reference
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -423,6 +423,6 @@ $closeAtFmt12 = $closeAt->format('m-d-Y g:i A T'); // e.g., 10-01-2025 12:00 AM
|
||||
<script type="module" src="/assets/js/name_validation.js"></script>
|
||||
<script type="module" src="/assets/js/age_validation.js"></script>
|
||||
<script type="module" src="/assets/js/phone_validation.js"></script>
|
||||
<script type="module" src="/assets/js/validate_student.js"></script>
|
||||
<script type="module" src="/assets/js/validate_student.js?v=<?= esc((string) filemtime(FCPATH . 'assets/js/validate_student.js')) ?>"></script>
|
||||
|
||||
<?= $this->endSection() ?>
|
||||
|
||||
@@ -1,22 +1,25 @@
|
||||
<div class="student-form border rounded p-3 mb-4 bg-light position-relative">
|
||||
<?php
|
||||
$publicGradeOptions = [
|
||||
'NA' => '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',
|
||||
];
|
||||
?>
|
||||
<button type="button" class="btn-close position-absolute end-0 top-0 m-2 js-remove-student" aria-label="Close"></button>
|
||||
<h5 class="mb-3 text-primary">Student Information</h5>
|
||||
<div class="col-md-12 mb-3">
|
||||
<label class="form-label fw-bold mb-2 d-block">
|
||||
Was your child enrolled in Al Rahma Sunday School last year? <span class="text-danger">*</span>
|
||||
</label>
|
||||
|
||||
<div class="d-flex align-items-center flex-wrap gap-3">
|
||||
<div class="form-check ps-3">
|
||||
<input class="form-check-input" type="radio" name="last_year_0" value="yes" data-base-name="last_year" required autocomplete="off">
|
||||
<label class="form-check-label">Yes</label>
|
||||
</div>
|
||||
<div class="form-check ps-3">
|
||||
<input class="form-check-input" type="radio" name="last_year_0" value="no" data-base-name="last_year" required autocomplete="off">
|
||||
<label class="form-check-label">No</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" name="last_year_0" value="no" data-last-year-default>
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label">First Name <span class="text-danger">*</span></label>
|
||||
@@ -50,12 +53,14 @@
|
||||
<small class="text-danger age-error d-none">Student must be between 5 and 18 years old.</small>
|
||||
</div>
|
||||
<div class="col-6 mb-3">
|
||||
<label class="form-label grade-label">Last Year Grade <span class="text-danger">*</span></label>
|
||||
<label class="form-label grade-label">Public School Last Year Grade <span class="text-danger">*</span></label>
|
||||
<select class="form-select dynamic-grade grade-select"
|
||||
name="registration_grade[]"
|
||||
required data-base-name="registration_grade"
|
||||
disabled>
|
||||
required data-base-name="registration_grade">
|
||||
<option value="">Select Grade</option>
|
||||
<?php foreach ($publicGradeOptions as $value => $label): ?>
|
||||
<option value="<?= esc($value) ?>"><?= esc($label) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
@@ -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 = '<option value="">Select Grade</option>';
|
||||
gradeSelect.value = '';
|
||||
gradeSelect.disabled = true; // keep disabled until a radio is chosen
|
||||
gradeLabel.innerHTML = 'Last Year Grade <span class="text-danger">*</span>';
|
||||
gradeSelect.disabled = false;
|
||||
gradeLabel.innerHTML = 'Public School Last Year Grade <span class="text-danger">*</span>';
|
||||
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 <span class="text-danger">*</span>';
|
||||
populateSelect(gradeSelect, gradeOptions.alrahma);
|
||||
} else if (type === 'no') {
|
||||
gradeLabel.innerHTML = 'Public School Last Year Grade <span class="text-danger">*</span>';
|
||||
populateSelect(gradeSelect, gradeOptions.public);
|
||||
} else {
|
||||
resetGradeSelect(gradeSelect, gradeLabel);
|
||||
}
|
||||
gradeLabel.innerHTML = 'Public School Last Year Grade <span class="text-danger">*</span>';
|
||||
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);
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
</script>
|
||||
|
||||
@@ -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 = '<option value="">Select Grade</option>';
|
||||
gradeSelect.disabled = true;
|
||||
gradeLabel.innerHTML = 'Last Year Grade <span class="text-danger">*</span>';
|
||||
gradeSelect.disabled = false;
|
||||
gradeLabel.innerHTML = 'Public School Last Year Grade <span class="text-danger">*</span>';
|
||||
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
|
||||
});
|
||||
});
|
||||
})();
|
||||
})();
|
||||
|
||||
@@ -3,11 +3,7 @@
|
||||
|
||||
<h4 class="form-title">Student-# Information</h4>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Was your child with us last year? *</label><br>
|
||||
<input type="radio" class="lastYearRadio" name="last_year_#" value="yes" required> Yes
|
||||
<input type="radio" class="lastYearRadio" name="last_year_#" value="no" required> No
|
||||
</div>
|
||||
<input type="hidden" name="last_year_#" value="no" data-last-year-default>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>First Name</label>
|
||||
@@ -28,6 +24,20 @@
|
||||
<label>School Grade</label>
|
||||
<select name="registration_grade[]" class="form-select dynamic-grade" required>
|
||||
<option value="">Select School Grade</option>
|
||||
<option value="NA">Not enrolled in public school</option>
|
||||
<option value="KG">Pre-K / Kindergarten</option>
|
||||
<option value="1">Grade 1</option>
|
||||
<option value="2">Grade 2</option>
|
||||
<option value="3">Grade 3</option>
|
||||
<option value="4">Grade 4</option>
|
||||
<option value="5">Grade 5</option>
|
||||
<option value="6">Grade 6</option>
|
||||
<option value="7">Grade 7</option>
|
||||
<option value="8">Grade 8</option>
|
||||
<option value="9">Grade 9</option>
|
||||
<option value="10">Grade 10</option>
|
||||
<option value="11">Grade 11</option>
|
||||
<option value="12">Grade 12</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
@@ -44,4 +54,4 @@
|
||||
<button type="button" class="btn btn-danger remove-student">Remove</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user