Created
January 9, 2014 10:26
-
-
Save LukasRychtecky/8332181 to your computer and use it in GitHub Desktop.
Best practice - i tohle jsou studenti schopni mi odevzdat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class indexController extends Controller { | |
public $head = 1; | |
var $name = "Vytvoření účtu"; | |
/** | |
* Automatický text pro template - titulek (TITLE) | |
*/ | |
public function name() { | |
echo ' - ' . $this->name; | |
} | |
/** | |
* Automatický text pro template - text | |
*/ | |
public function index() { | |
?><h2>Vytvořte si svůj účet</h2> | |
<form name="login" action="index.php?url=createAccount" method="post" onsubmit='return check(this);' accept-charset="utf-8"> | |
<ul> | |
<li><input type="text" name="nick" id ="nick" placeholder="login" value="" tabindex="1" onclick ="isFreeNick(this.value)" onkeyup="isFreeNick(this.value)" required><label for="usermail">Nickname</label></li> | |
<li><input type="password" name="pass" id ="pass" placeholder="password" value="" tabindex="2" required><label for="password">Password</label></li> | |
<li><input type="email" name="mail" id="mail" placeholder="email@email.com" value="" tabindex="3"onclick ="isFreeMail(this.value)" onkeyup="isFreeMail(this.value)" required><label for="password">Email</label></li> | |
<li><input type="submit" value="Login" tabindex="4"></li> | |
</ul> | |
</form> | |
<p>Zde se zobrazí, zda je NICK již použit: <span id="nickTell"></span></p> | |
<p>Zde se zobrazí, zda je MAIL již použit: <span id="mailTell"></span></p> | |
<?php | |
} | |
/** | |
* Pozměněn pouze pro zobrazení LogIn | |
*/ | |
public function aside() { | |
$aside = new Aside(); | |
$aside->makeLogIn(); | |
} | |
/** | |
* Hlavička vložená do template - použito pro JS (s AJAX) | |
*/ | |
public function header() { | |
?> | |
<script> | |
document.onload = function() { | |
<?php | |
if(isset($_SESSION['nick']))echo "document.getElementById('nick').value = ".$_SESSION['nick']; | |
if(isset($_SESSION['email']))echo "document.getElementById('mail').value = ".$_SESSION['email']; | |
?>; | |
}; | |
function isFreeNick(str) | |
{ | |
if (str.length == 0) | |
{ | |
document.getElementById("nickTell").innerHTML = ""; | |
return; | |
} | |
var xmlhttp = new XMLHttpRequest(); | |
xmlhttp.onreadystatechange = function() | |
{ | |
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) | |
{ | |
if (xmlhttp.responseText === "Není volný!") { | |
document.getElementById("nickTell").style.color = "red"; | |
} | |
document.getElementById("nickTell").innerHTML = xmlhttp.responseText; | |
} | |
} | |
xmlhttp.open("GET", "index.php?url=help/nick/" + str, true); | |
xmlhttp.send(); | |
} | |
function isFreeMail(str) | |
{ | |
if (str.length == 0) | |
{ | |
document.getElementById("mailTell").innerHTML = ""; | |
return; | |
} | |
var xmlhttp = new XMLHttpRequest(); | |
xmlhttp.onreadystatechange = function() | |
{ | |
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) | |
{ | |
if (xmlhttp.responseText === "Není volný!") { | |
document.getElementById("mailTell").style.color = "red"; | |
} | |
document.getElementById("mailTell").innerHTML = xmlhttp.responseText; | |
} | |
} | |
xmlhttp.open("GET", "index.php?url=help/mail/" + str, true); | |
xmlhttp.send(); | |
} | |
function check(send) | |
{ | |
if (document.getElementById("nickTell").innerHTML === "" && send.nick.value !== "" || | |
document.getElementById("mailTell").innerHTML === "" && send.mail.value !== "" || | |
document.getElementById("nickTell").innerHTML === "Není volný!" || | |
document.getElementById("mailTell").innerHTML === "Není volný!") { | |
return false; | |
} | |
} | |
</script> | |
<?php | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment