How To Submit An HTML Form Using PHP?

try

<form id="frmMain" action="ht.php" method="post">
    <a href="#" onclick="document.forms['frmMain'].submit();">Submit</a>
</form>

Using jQuery, its rather easy:

$('form .submit-link').on({
    click: function (event) {
        event.preventDefault();
        $(this).closest('form').submit();
    }
});

Then you just code as normal, assigning the class submit-link to the form submission links:

<form action="script.php" method="post">
    <input type="text" name="textField" />
    <input type="hidden" name="hiddenField" value="foo" />
    <a href="#" class="submit-link">Submit</a>
</form>

I find this method useful, if you want to maintain an aesthetic theme across the site using links rather than traditional buttons, since there's no inline scripting.

Here's a JSFiddle, although it doesn't submit anywhere.


You can't just do document.url.submit(), it doesn't work like that.

Try this:

<form id="myForm" action="ht.php" method="post">
    <input type="hidden" name="someName" value="helloworld" />
    <a href="#" onclick="document.getElementById('myForm').submit();">Submit</a>
</form>

That should work!