I want to create a form that calls PHP code within the same php file on submit.
Reading this, Why use $_SERVER['PHP_SELF'] instead of "", it seems I can use action=""
instead of $_SERVER['PHP_SELF'];
to do this.
If that's so, when I click submit, why isn't this PHP code at the top of the file executed?
if(isset($_POST['submit'])) {
echo "submitted";
}
It should say submitted
on the page.
In Google DevTools, the network
tab doesn't show that the file is being called, just that the page is reloaded.
Form snippet:
<div id="contactForm">
<form role="form" action="" method='post' accept-charset='UTF-8'>
<div class="row">
<div class="form-group col-xs-12 floating-label-form-group">
<input class="form-control" type="text" name="name" placeholder="Name">
</div>
</div>
<div class="row">
<div class="form-group col-xs-12">
<button type="submit" class="btn btn-lg btn-success">Send</button>
</div>
</div>
</form>