2026-04-13 19:04:12 +05:30

200 lines
7.3 KiB
PHP

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Register</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="<?= base_url('css/app.css') ?>">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">
</head>
<body class="app-body app-page--auth">
<?php $validationErrors = validation_errors(); ?>
<div class="card auth-card shadow">
<div class="card-body">
<h2 class="text-center mb-4 auth-title">Create account</h2>
<?php if (session()->getFlashdata('error')): ?>
<div class="alert alert-danger app-alert"><?= esc(session()->getFlashdata('error')) ?></div>
<?php endif; ?>
<form method="post" action="<?= base_url('register') ?>" class="app-form" novalidate>
<?= csrf_field() ?>
<div class="mb-3">
<?php
echo view('components/name_field', [
'fieldName' => 'first_name',
'fieldLabel' => 'First name',
'fieldId' => 'first_name',
'fieldValue' => old('first_name', $first_name ?? ''),
'required' => true,
'validationErrors' => $validationErrors,
'placeholder' => 'Enter first name'
]);
?>
</div>
<div class="mb-3">
<?php
echo view('components/name_field', [
'fieldName' => 'last_name',
'fieldLabel' => 'Last name',
'fieldId' => 'last_name',
'fieldValue' => old('last_name', $last_name ?? ''),
'required' => true,
'validationErrors' => $validationErrors,
'placeholder' => 'Enter last name'
]);
?>
</div>
<div class="mb-3">
<label class="form-label" for="email">Email <span class="text-danger">*</span></label>
<input type="email" name="email" id="email" value="<?= esc(old('email')) ?>"
class="form-control <?= isset($validationErrors['email']) ? 'is-invalid' : '' ?>"
placeholder="Email address" autocomplete="email" required>
<?= validation_show_error('email') ?>
</div>
<div class="mb-3">
<label class="form-label" for="phone">
Phone <span class="text-danger">*</span>
</label>
<div class="input-group">
<span class="input-group-text">+91</span>
<input type="tel" name="phone" id="phone" pattern="[0-9]{10}" maxlength="10"
value="<?= esc(old('phone')) ?>"
class="form-control <?= isset($validationErrors['phone']) ? 'is-invalid' : '' ?>"
placeholder="Enter phone number"
autocomplete="tel"
required>
</div>
<?= validation_show_error('phone') ?>
</div>
<div class="mb-3">
<label class="form-label">Password <span class="text-danger">*</span></label>
<div class="position-relative">
<input type="password" id="password" name="password"
class="form-control pe-5"
placeholder="Enter strong password"
required>
<span class="position-absolute top-50 end-0 translate-middle-y me-3"
style="cursor:pointer;"
onclick="togglePassword()">
<i id="eyeIcon" class="fa fa-eye"></i>
</span>
</div>
<!-- Password Strength Text -->
<small id="strengthText" class="mt-2 d-block"></small>
<!-- Rules -->
<ul class="small mt-2" id="passwordRules">
<li id="length" class="text-danger">At least 8 characters</li>
<li id="uppercase" class="text-danger">One uppercase letter</li>
<li id="lowercase" class="text-danger">One lowercase letter</li>
<li id="number" class="text-danger">One number</li>
<li id="special" class="text-danger">One special character</li>
</ul>
</div>
<p class="small text-muted mb-4">Register as a <strong>patient</strong> to book appointments.</p>
<button type="submit" class="btn btn-app-primary w-100">Register</button>
</form>
<div class="text-center mt-4">
<p class="auth-divider-text mb-2">Already have an account?</p>
<a href="<?= base_url('/') ?>" class="btn-app-secondary">Back to login</a>
</div>
</div>
</div>
<script src="<?= base_url('js/script.js') ?>"></script>
<script>
const password = document.getElementById("password");
password.addEventListener("input", function () {
const val = password.value;
const length = document.getElementById("length");
const upper = document.getElementById("uppercase");
const lower = document.getElementById("lowercase");
const number = document.getElementById("number");
const special = document.getElementById("special");
const strengthText = document.getElementById("strengthText");
let strength = 0;
// Rules check
if (val.length >= 8) {
length.classList.replace("text-danger", "text-success");
strength++;
} else {
length.classList.replace("text-success", "text-danger");
}
if (/[A-Z]/.test(val)) {
upper.classList.replace("text-danger", "text-success");
strength++;
} else {
upper.classList.replace("text-success", "text-danger");
}
if (/[a-z]/.test(val)) {
lower.classList.replace("text-danger", "text-success");
strength++;
} else {
lower.classList.replace("text-success", "text-danger");
}
if (/[0-9]/.test(val)) {
number.classList.replace("text-danger", "text-success");
strength++;
} else {
number.classList.replace("text-success", "text-danger");
}
if (/[^A-Za-z0-9]/.test(val)) {
special.classList.replace("text-danger", "text-success");
strength++;
} else {
special.classList.replace("text-success", "text-danger");
}
// Strength display
if (strength <= 2) {
strengthText.innerHTML = "Weak Password ❌";
strengthText.className = "text-danger";
} else if (strength <= 4) {
strengthText.innerHTML = "Medium Password ⚠️";
strengthText.className = "text-warning";
} else {
strengthText.innerHTML = "Strong Password ✅";
strengthText.className = "text-success";
}
});
function togglePassword() {
const password = document.getElementById("password");
const icon = document.getElementById("eyeIcon");
if (password.type === "password") {
password.type = "text";
icon.classList.remove("fa-eye");
icon.classList.add("fa-eye-slash");
} else {
password.type = "password";
icon.classList.remove("fa-eye-slash");
icon.classList.add("fa-eye");
}
}
</script>
</body>
</html>