使用javascript提交表单,将其保存到$ _POST

I'm trying to use an a tag to submit a form but the PHP doesn't seem to react:

    <html>
<head>

</head>
<body>
<?php
if(isset($_POST['submit']))
    echo 'dog';
else
    echo 'cat';
$currentPage = 'test';
echo <<<eod
<form method='post' action='$currentPage.php' id='sign_in' style='margin: 0; padding: 0;'>
Username: <input type='text' name='username' style='width: 90px;'>
Password: <input type='text' name='password' style='width: 90px; border-right: 1px solid #bbb'>
<a id='sign_in_submit' name='submit'>Sign in</a>
</form>
eod;
?>
<script>
    var form = document.getElementById('sign_in');

    document.getElementById("sign_in_submit").addEventListener("click", function () {
        form.submit();
    });
</script>
</body>
</html>

tried three methods of submission via JS but none of them seem to work

Your submit a tag would not be included in the post data, so check for the existence of one of the input tags, say $_POST['username']

I have just tested your code. You are checking if submit field/button is sent over the form, but you do not have anything named submit in your form. You have got username and password, so changing your if(isset($_POST['submit'])) to if(isset($_POST['username'])) or if(isset($_POST)) will fix your issue.

try in javascript this:

document.sign_in.submit();

and make a submit button like this

<input type="submit" id='sign_in_submit' value="Sign in" name='submit'