form dynamique avec jquery
This commit is contained in:
parent
100b22a0c1
commit
aca024783e
4
post.php
4
post.php
|
@ -3,7 +3,7 @@ require_once("function.php");
|
||||||
if (session_status() == PHP_SESSION_NONE) {
|
if (session_status() == PHP_SESSION_NONE) {
|
||||||
session_start();
|
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,}))$/';
|
$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}$/';
|
$pwPatern = '/^[a-z]{8,16}$/';
|
||||||
$loginPatern = '/^[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"]))
|
if(userExist($_POST["login"]))
|
||||||
{
|
{
|
||||||
$ret["return"] = "userExist";
|
$ret["return"] = "userExist";
|
||||||
|
$ret["register"] = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -56,6 +57,7 @@ elseif (isset($_POST["newUser"],$_POST["datene"], $_POST["email"], $_POST["pw"])
|
||||||
));
|
));
|
||||||
$req->closeCursor();
|
$req->closeCursor();
|
||||||
$ret["return"] = true;
|
$ret["return"] = true;
|
||||||
|
$ret["register"] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -62,7 +62,6 @@ $(function() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$("body").on("keyup change", ".login input, input .login", function(e) {
|
$("body").on("keyup change", ".login input, input .login", function(e) {
|
||||||
console.log("hoo");
|
|
||||||
login = ltrim($(this).val());
|
login = ltrim($(this).val());
|
||||||
input = $(this);
|
input = $(this);
|
||||||
td = $(this).parent();
|
td = $(this).parent();
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
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>
|
<head>
|
||||||
{% include 'header.html.twig' %}
|
{% include 'header.html.twig' %}
|
||||||
<link rel="stylesheet" href="./css/login.css?{{ date().timestamp }}" />
|
<link rel="stylesheet" href="./css/login.css?{{ date().timestamp }}" />
|
||||||
|
<script src="./script/login.js"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<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"] }}" />
|
<input type="hidden" id="slVal" value="{{ session["sl"] }}" />
|
||||||
<table id="allRecord">
|
<table id="allRecord">
|
||||||
<thead>
|
<thead>
|
||||||
|
|
Loading…
Reference in New Issue