Skip to content

Instantly share code, notes, and snippets.

@jshawl
Created March 27, 2014 17:01
Show Gist options
  • Save jshawl/9812543 to your computer and use it in GitHub Desktop.
Save jshawl/9812543 to your computer and use it in GitHub Desktop.
Ajax instead of captcha?
<!DOCTYPE html>
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
</head>
<body>
<form action='post.php' method='post'>
<input type='text' value='whatever' name='something'>
<button type='submit' class='js-submit'>Submit</button>
</form>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$('.js-submit').on('click', function(event){
event.preventDefault();
dataString = 'something='+$('[name="something"]').val();
$.ajax({
type: 'post',
url:'post.php',
data: dataString + '&human-initiated=true'
}).done(function( data ){
console.log(data);
});
});
</script>
</body>
</html><!-- by @jshawl -->
<?php
if ( $_POST['human-initiated']== true ){
echo 'A human submitted this form';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment