Skip to content

Instantly share code, notes, and snippets.

@aurorapar
Last active October 31, 2017 09:43
Show Gist options
  • Save aurorapar/9fc487beb86878e79d122a27c0fe25e1 to your computer and use it in GitHub Desktop.
Save aurorapar/9fc487beb86878e79d122a27c0fe25e1 to your computer and use it in GitHub Desktop.
$(document).ready( function() {
$( "#updateForm" ).submit(sendValues);
});
function sendValues(e)
{
data = $( "#updateForm" ).serialize();
var request = $.ajax({
url: "createaccount.php",
type: "POST",
data: {
"data": $( "#updateForm").serialize(),
},
dataType: "text"
});
request.done(function(msg) {
$( ".accountSuccess" ).html(msg);
});
request.fail(function(msg) {
alert("AJAX CALL FAILED");
});
e.preventDefault();
}
<?php
$data = $_POST['data'];
parse_str($data, $data);
foreach($data as $dataVar)
{
$key = array_search($dataVar, $data);
$dataVar = trim($dataVar, " \t\n\r\0\x0B");
$data[$key] = htmlspecialchars( strip_tags($dataVar) );
}
$test = $data['test'];
$answer = $data['answer'];
if($answer!=$test)
{
print "You don't appear to be human.";
}
?>
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>WoW Dev Platform</title>
<link href="css/style.css" rel="Stylesheet" type="text/css" />
<script
src="https://code.jquery.com/jquery-3.1.1.js"
integrity="sha256-16cdPddA6VdVInumRGo6IbivbERE8p7CQR3HzTBuELA="
crossorigin="anonymous"></script>
<script src="js/ajaxform.js"></script>
</head>
<body>
<header>
<div id="banner" class="">
<div id="banner-content">
</div>
</div>
</header>
<div id="content" class="">
<form id="updateForm">
<label>Email:</label><br>
<input id="email" type="email" name="email"><br><br>
<label >Account:</label><br>
<input id="account" type="text" name="account"><br><br>
<label >Password</label><br>
<input id="password" type="password" name="password"><br><br>
<?php
$low = rand(1,10);
$high = rand(1,10);
$answer = $low + $high;
?>
<label >Are you a human? What is <?=$low;?> + <?=$high;?>?</label><br>
<input id="test" type="number" name="test"><br><br>
<input id="answer" type="hidden" name="answer" value="<?=$answer;?>">
<button id="update">Submit</button>
</form>
<div class="accountSuccess">
</div>
</div>
<p></p>
<p></p>
<p></p>
<footer>
<div class="">
Copyright 2016<br>
Aurora Pariseau
</div>
</footer>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment