Commit aca02478 authored by adri's avatar adri
Browse files

form dynamique avec jquery

parent 100b22a0
......@@ -3,7 +3,7 @@ require_once("function.php");
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
//var_dump($_POST);
$emailPatern = '/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/';
$pwPatern = '/^[a-z]{8,16}$/';
$loginPatern = '/^[a-z]{8,16}$/';
......@@ -41,6 +41,7 @@ elseif (isset($_POST["newUser"],$_POST["datene"], $_POST["email"], $_POST["pw"])
if(userExist($_POST["login"]))
{
$ret["return"] = "userExist";
$ret["register"] = false;
}
else
{
......@@ -56,6 +57,7 @@ elseif (isset($_POST["newUser"],$_POST["datene"], $_POST["email"], $_POST["pw"])
));
$req->closeCursor();
$ret["return"] = true;
$ret["register"] = true;
}
}
else
......
......@@ -62,7 +62,6 @@ $(function() {
}
});
$("body").on("keyup change", ".login input, input .login", function(e) {
console.log("hoo");
login = ltrim($(this).val());
input = $(this);
td = $(this).parent();
......
passwordPatern = /^[a-zA-Z0-9]{8,16}$/;
loginPatern = /^[a-z]{8,16}$/
mailPatern = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; //https://emailregex.com/
datePatern = /^\d{4}[\/\-](?:\d{1}|1[012]|0\d)[\/\-](?:\d{1}|[123]\d|0\d)/
$(function() {
$('form').on('submit',function(e) {
e.preventDefault();
var data = $(this).serialize();
var url = $(this).attr('action')
if(url == "./post.php")
if (mailPatern.test($(".email input").val()) && passwordPatern.test($(".pw input").val()) && $(".pw2 input").val() == $(".pw input").val() && loginPatern.test($(".login input").val()))
{
}
else {
swal("Oops", "Something wrong in the form ", "error");
return false;
}
$.ajax({
type: 'post',
url: url,
data: data,
dataType: "json",
success: function(data) {
console.log(data);
if (typeof(data.register) != "undefined" && data.register !== null) {
if (data.register) {
swal("Good job!", "You are registered !", "success");
$('form').animate({
height: "toggle",
opacity: "toggle"
}, "slow");
} else {
swal("Oops", "Something wrong in the form : " + data.return, "error");
}
} else if (typeof(data.login) != "undefined" && data.login !== null) {
if(data.login)
{
swal("Good job!", "You are logged !\nYou're redirect in 5 seconds", "success");
var delay = 5000;
setTimeout(function(){ window.location = "/bil/"; }, delay);
}
else
swal("Oops", "Something wrong in the form", "error");
}
}
});
// send xhr request
});
});
......@@ -3,6 +3,7 @@
<head>
{% include 'header.html.twig' %}
<link rel="stylesheet" href="./css/login.css?{{ date().timestamp }}" />
<script src="./script/login.js"></script>
</head>
<body>
......
......@@ -4,7 +4,7 @@
</head>
<body>
<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for names..">
<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for login..">
<input type="hidden" id="slVal" value="{{ session["sl"] }}" />
<table id="allRecord">
<thead>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment