The issue seems to be the action in the submit button which was
<?php echo $_SERVER["PHP_SELF"];?>
and I changed it to
<?php echo esc_attr($_SERVER['REQUEST_URI']);?>
With this I can click on the button and the page is reloaded. However if any values in the text inputs are set I again get a 404 without redirecting to index.php but to the same url again.
My complete slimed down w3c example is:
if ($_SERVER["REQUEST_METHOD"] == "POST")
$name = $_POST["name"];
<form method="post" action="<?php echo esc_attr($_SERVER['REQUEST_URI']);?>">
Name: <input type="text" name="name" value="<?php echo $name;?>"><br>
<input type="submit" name="submit" value="Submit">
Thanks for any help.