I am trying to create a little PHP website that has a checkbox and a button. When you click the button, the text is supposed to appear to tell you if the checkbox is checked or not. I'm not sure why, but I am having a lot of trouble trying to figure out how to do this solely with HTML and PHP. My thought process on how to do this is that when the user clicks the button, the button calls a function in PHP. The function's purpose is to check to see if the checkbox is set through a simple if statement and echo are out the proper response. Here is the code I have for this scenario.
<!DOCTYPE html>
<html>
<head>
<title>Checked Boxes</title>
</head>
<body>
<input type="checkbox" name="checked_box_check" value="checked_box_check">Check This Box!<br> <br>
<form method="post">
<input type="submit" name="submit_checked" class="button" value="Check if checkbox is checked"/>
</form>
<?php
function checkFunction(){
if (isset($_POST['checked_box_check'])){
echo("It's checked!");
} else {
echo("It's not checked!");
}
}
if(isset($_POST['submit_checked'])) {
checkFunction();
}
?>
</body>
</html>
I'm sorry if this seems self-explanatory, but I can't figure this out and would really appreciate any help! Thank you.