Created
March 1, 2020 17:46
-
-
Save daveh/ff121a0bfcfeebcde82081cd2f32e935 to your computer and use it in GitHub Desktop.
Checking if a form has been submitted in PHP (https://youtu.be/tORiyyMds1M)
This file contains hidden or 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 | |
// Code to accompany this video: https://youtu.be/tORiyyMds1M | |
// if ($_POST) { | |
// if (isset($_POST['sendButton'])) { | |
if($_SERVER['REQUEST_METHOD'] == 'POST') { | |
exit("form submitted"); | |
} | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Form example</title> | |
</head> | |
<body> | |
<h1>Detect form submission</h1> | |
<form method="post"> | |
<div> | |
<input type="checkbox" id="agree" name="terms"> | |
<label for="agree">I agree</label> | |
</div> | |
<!-- <button type="submit" name="sendButton">Send</button> --> | |
<button type="submit">Send</button> | |
</form> | |
<button id="submitJS">Submit using script</button> | |
<script> | |
document.getElementById("submitJS").addEventListener("click", function(event) { | |
document.querySelector("form").submit(); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment