Skip to content

Instantly share code, notes, and snippets.

@mebjas
Created September 3, 2015 03:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mebjas/fb1f258cc4ac360ca63d to your computer and use it in GitHub Desktop.
Save mebjas/fb1f258cc4ac360ca63d to your computer and use it in GitHub Desktop.
<?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