Added join (adhesion) form
This commit is contained in:
parent
5a70032bb3
commit
0e82d768d5
59
public/join/index.php
Normal file
59
public/join/index.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
session_start();
|
||||
$root = realpath($_SERVER['DOCUMENT_ROOT']);
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Les Cocottes Minutes</title>
|
||||
<link rel="stylesheet" href="/styles/style.css">
|
||||
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
|
||||
<link rel="stylesheet" href="//unpkg.com/leaflet@1.7.1/dist/leaflet.css"
|
||||
integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A=="
|
||||
crossorigin=""/>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<?php include("$root/menu.php");?>
|
||||
<?php include("$root/header.php");?>
|
||||
</div>
|
||||
<section>
|
||||
<div class="container flip reduced"></div>
|
||||
<div class="container join">
|
||||
<h2>Adhérer aux Cocottes Minutes</h2>
|
||||
<form action="join.php" method="POST">
|
||||
<label for="name">Nom*</label>
|
||||
<input type="text" name="name" id="name" placeholder="Mister Cot" required>
|
||||
<label for="number">Numéro étudiant</label>
|
||||
<input type="text" name="number" id="number">
|
||||
<label for="email">Email*</label>
|
||||
<input type="email" name="email" id="email" placeholder="cot.cot.cot@cocottes-minutes.fr" required>
|
||||
<input type="submit" name="submit" value="Je deviens une Cocotte !">
|
||||
</form>
|
||||
<p>* obligatoire</p>
|
||||
<?php
|
||||
if (isset($_SESSION['error_msg']) && $_SESSION['error_msg'] != "")
|
||||
{
|
||||
?>
|
||||
<div class="error">
|
||||
<?=$_SESSION['error_msg']?>
|
||||
</div>
|
||||
<?php
|
||||
$_SESSION['error_msg'] = "";
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<div class="container flip reduced"></div>
|
||||
</section>
|
||||
</div>
|
||||
<?php include("$root/footer.php");?>
|
||||
<script src="/scripts/script.js"></script>
|
||||
<script src="//unpkg.com/leaflet@1.7.1/dist/leaflet.js"
|
||||
integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA=="
|
||||
crossorigin=""></script>
|
||||
<script src="/scripts/map.js"></script>
|
||||
</body>
|
||||
</html>
|
85
public/join/join.php
Normal file
85
public/join/join.php
Normal file
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
$root = realpath($_SERVER['DOCUMENT_ROOT']);
|
||||
session_start();
|
||||
function create_member($name, $number, $email)
|
||||
{
|
||||
$root = realpath($_SERVER['DOCUMENT_ROOT']);
|
||||
require("$root/config.php");
|
||||
try{
|
||||
$db = new PDO("pgsql:host=$host;dbname=$database",
|
||||
$user,
|
||||
$password,
|
||||
array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
|
||||
));
|
||||
}catch (Exception $e){
|
||||
die("Error : ".$e->getMessage());
|
||||
}
|
||||
// Check if table exitst
|
||||
$req = $db->prepare('CREATE TABLE IF NOT EXISTS members (id SERIAL PRIMARY KEY, name varchar(125) NOT NULL UNIQUE, student_number varchar(8) UNIQUE, email varchar(125) UNIQUE)');
|
||||
$req->execute();
|
||||
if (strlen($name) > 125)
|
||||
{
|
||||
$_SESSION['error_msg'] .= "Le nom entré est trop long.\n";
|
||||
}
|
||||
if (strlen($email) > 125)
|
||||
{
|
||||
$_SESSION['error_msg'] .= "L'email entré est trop long.\n";
|
||||
}
|
||||
if (strlen($number) > 8)
|
||||
{
|
||||
$_SESSION['error_msg'] .= "Votre numéro d'étudiant semble incorrect (il comporte plus de 8 caractères.\n";
|
||||
}
|
||||
if ($_SESSION['error_msg'] == "")
|
||||
{
|
||||
try {
|
||||
$req = $db->prepare('INSERT INTO members (name, student_number, email) VALUES (?, ?, ?)');
|
||||
$req->execute(array($name, $number, $email));
|
||||
} catch (Exception $e) {
|
||||
$_SESSION['error_msg'] .= $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$_SESSION['error_msg'] = "";
|
||||
if (isset($_POST['submit']))
|
||||
{
|
||||
if (isset($_POST['name']) and $_POST['name'] != "")
|
||||
{
|
||||
$name = $_POST['name'];
|
||||
$_SESSION['name'] = $name;
|
||||
} else
|
||||
{
|
||||
$_SESSION['error_msg'] .= "Vous n'avez pas entré de nom.\n";
|
||||
}
|
||||
if (isset($_POST['number']))
|
||||
{
|
||||
$number = $_POST['number'];
|
||||
} else {
|
||||
$number = "";
|
||||
}
|
||||
if (isset($_POST['email']) and $_POST['email'] != "")
|
||||
{
|
||||
$email = $_POST['email'];
|
||||
} else {
|
||||
$_SESSION['error_msg'] .= "Vous n'avez pas entré d'adresse mail.\n";
|
||||
}
|
||||
} else
|
||||
{
|
||||
$_SESSION['error_msg'] .= "Attention, vous n'avez pas soumis le formulaire d'adhésion.\n";
|
||||
}
|
||||
|
||||
if ($_SESSION['error_msg'] == "")
|
||||
{
|
||||
create_member($name, $number, $email);
|
||||
}
|
||||
if ($_SESSION['error_msg'] != "")
|
||||
{
|
||||
$_SESSION['error_msg'] .= "Veuillez réessayer.";
|
||||
header('Location: /join');
|
||||
} else {
|
||||
header('Location: /');
|
||||
}
|
||||
?>
|
Loading…
Reference in New Issue
Block a user