107 lines
3.4 KiB
PHP
107 lines
3.4 KiB
PHP
<?php
|
|
require_once __DIR__ . '/shared/header.php';
|
|
require_once __DIR__ . '/db/config.php';
|
|
|
|
$errors = [];
|
|
$full_name = '';
|
|
$email = '';
|
|
$phone = '';
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|
$full_name = trim($_POST['full_name']);
|
|
$email = trim($_POST['email']);
|
|
$phone = trim($_POST['phone']);
|
|
$password = $_POST['password'];
|
|
$confirm_password = $_POST['confirm_password'];
|
|
|
|
if (empty($full_name)) {
|
|
$errors[] = 'error_full_name_required';
|
|
}
|
|
|
|
if (empty($email)) {
|
|
$errors[] = 'error_email_required';
|
|
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
|
$errors[] = 'error_invalid_email';
|
|
}
|
|
|
|
if (empty($phone)) {
|
|
$errors[] = 'error_phone_required';
|
|
}
|
|
|
|
if (empty($password)) {
|
|
$errors[] = 'error_password_required';
|
|
}
|
|
|
|
if ($password !== $confirm_password) {
|
|
$errors[] = 'error_passwords_no_match';
|
|
}
|
|
|
|
if (empty($errors)) {
|
|
try {
|
|
$pdo = db();
|
|
|
|
$stmt = $pdo->prepare("SELECT * FROM users WHERE email = ?");
|
|
$stmt->execute([$email]);
|
|
$existing_user = $stmt->fetch();
|
|
|
|
if ($existing_user) {
|
|
$errors[] = 'error_email_exists';
|
|
} else {
|
|
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
|
|
|
|
$stmt = $pdo->prepare("INSERT INTO users (full_name, email, phone, password) VALUES (?, ?, ?, ?)");
|
|
$stmt->execute([$full_name, $email, $phone, $hashed_password]);
|
|
|
|
header("Location: login.php?registration=success");
|
|
exit;
|
|
}
|
|
} catch (PDOException $e) {
|
|
$errors[] = "error_database";
|
|
}
|
|
}
|
|
}
|
|
|
|
$pageTitle = __('signup_title');
|
|
?>
|
|
|
|
<div class="form-container">
|
|
<h1><?= __('signup_title') ?></h1>
|
|
|
|
<?php if (!empty($errors)): ?>
|
|
<div class="errors">
|
|
<?php foreach ($errors as $error): ?>
|
|
<p><?php echo htmlspecialchars(__($error)); ?></p>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<form action="signup.php" method="post">
|
|
<div class="form-group">
|
|
<label for="full_name"><?= __('full_name_label') ?></label>
|
|
<input type="text" id="full_name" name="full_name" required value="<?php echo htmlspecialchars($full_name); ?>">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="email"><?= __('email_address_label') ?></label>
|
|
<input type="email" id="email" name="email" required value="<?php echo htmlspecialchars($email); ?>">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="phone"><?= __('phone_number_label') ?></label>
|
|
<input type="tel" id="phone" name="phone" required value="<?php echo htmlspecialchars($phone); ?>">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="password"><?= __('password_label') ?></label>
|
|
<input type="password" id="password" name="password" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="confirm_password"><?= __('confirm_password_label') ?></label>
|
|
<input type="password" id="confirm_password" name="confirm_password" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<button type="submit" class="btn btn-primary" style="width: 100%;"><?= __('signup_button') ?></button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
|
|
<?php
|
|
require_once __DIR__ . '/shared/footer.php';
|
|
?>
|