Created
September 3, 2015 03:41
-
-
Save mebjas/fb1f258cc4ac360ca63d to your computer and use it in GitHub Desktop.
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 | |
include __DIR__ .'/libs/csrf/csrfprotector.php'; | |
csrfprotector::init(); | |
if (isset($_POST['field1'])) { | |
echo 'success'; | |
exit; | |
} | |
?> | |
<html> | |
<head> | |
<title>csrfp test</title> | |
<body> | |
<form action="./sample.php" method="POST" id="form-request"> | |
<input type="text" name="field1" placeholder="field1" value="field1"><br> | |
<input type="text" name="field2" placeholder="field2" value="field2"><br> | |
<input type="submit" name="submit"> | |
</form> | |
</body> | |
<script src="jquery.js"></script> | |
<script> | |
$("#form-request").submit(function() { | |
$.ajax({ | |
type: "POST", | |
url: $(this).attr('action'), | |
data: $(this).serialize(), | |
complete: function(data, status) { | |
if(status === "success") { | |
alert("Request for landing page sent successfully."); | |
updateRequests(); | |
} else { | |
alert("Failed to send request for landing page. Please check you have a landing page for that domain already.", true); | |
} | |
} | |
}); | |
return false; // avoid to execute the actual submit of the form. | |
}); | |
</script> | |
</head> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment