I am writing page-contact.php for a WordPress website contact page. Where I insert form.php through the following code snippet
<?php
include ('form.php');
But running over the localhost, throw a 404 error. While accessing form.php in browser work fine as expected.
<form id="contact" action="<?php htmlspecialchars($_SERVER["PHP_SELF"]) ?>" method="post">
// some code here
</form>
This is the inside the form.php
You can use the absolute path (due to your example this example assumes your form.php is in the same directory. Otherwise you´d need to adjust the path):
include __DIR__ . DIRECTORY_SEPARATOR . 'form.php';
In the form.php, you have $_SERVER['PHP_SELF'] . I think due to security issues it would be better to use
<form method="POST" action="<?php echo $_SERVER['REQUEST_URI']; ?>" >