Spaces:
Running
Running
File size: 5,294 Bytes
c8063c7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
{% extends "base.html" %}
{% block title %}Registration Page{% endblock %}
{% block content %}
<style>
.card-custom {
width: 600px;
margin: auto;
}
</style>
<div class="container mt-5 d-flex justify-content-center">
<div class="card card-custom">
<div class="card-body">
<form id="registrationForm" method="POST" onsubmit="return validateAndSubmitForm(event)">
<div class="form-group row">
<label for="inputName" class="col-sm-4 col-form-label">Student Name</label>
<div class="col-sm-8">
<input type="text" class="form-control" id="inputName" name="name" placeholder="Enter Full Name" oninput="validateForm()">
</div>
</div>
<div class="form-group row">
<label for="inputID" class="col-sm-4 col-form-label">Student ID Number</label>
<div class="col-sm-8">
<input type="text" class="form-control" id="inputID" name="student_id" placeholder="Enter Student ID Number" oninput="validateForm()">
</div>
</div>
<div class="form-group row">
<div class="col-sm-12 text-center">
<video id="webcam" autoplay style="display:none;"></video>
<canvas id="canvas" style="display:none;"></canvas>
<input type="hidden" name="photos" id="photos">
</div>
</div>
<br>
<div class="form-group row">
<div class="col-12 text-center">
<button type="button" class="btn btn-secondary" onclick="location.href='/'">Back</button>
<button type="submit" class="btn btn-primary" id="registerButton" disabled>Register</button>
</div>
</div>
</form>
</div>
</div>
</div>
<!-- Custom Alert Modal -->
<div class="modal fade" id="alertModal" tabindex="-1" role="dialog" aria-labelledby="alertModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="alertModalLabel">Alert</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body" id="alertModalBody">
<!-- Alert message will be inserted here -->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script>
function validateForm() {
var inputName = document.getElementById('inputName').value.trim();
var inputID = document.getElementById('inputID').value.trim();
var registerButton = document.getElementById('registerButton');
if (inputName !== '' && inputID !== '') {
registerButton.disabled = false;
} else {
registerButton.disabled = true;
}
}
function showAlert(message) {
document.getElementById('alertModalBody').innerText = message;
$('#alertModal').modal('show');
}
function validateAndSubmitForm(event) {
event.preventDefault(); // Prevent form submission
var inputName = document.getElementById('inputName').value.trim();
var inputID = document.getElementById('inputID').value.trim();
if (inputName === '' || inputID === '') {
showAlert("Both fields are required.");
return false; // Prevent form submission
}
fetch(`/check_student_id?student_id=${inputID}`)
.then(response => response.json())
.then(data => {
if (data.directory_exists) {
showAlert('Student is already registered in the database.');
} else {
var formData = new FormData(document.getElementById('registrationForm'));
fetch('/register', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
if (data.success) {
window.location.href = `/capture?student_id=${data.student_id}`;
} else {
showAlert('Registration failed. Please try again.');
}
})
.catch(error => console.error('Error:', error));
}
})
.catch(error => console.error('Error:', error));
return false; // Prevent form default submission
}
document.addEventListener('DOMContentLoaded', function() {
validateForm(); // Initial validation in case fields are pre-filled
});
</script>
{% endblock %}
|