Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ethar's avatar
Level 5

auto submit form

i want to auto submit form when visit page, but the following code is not working, plz any help

<form method="post" onload="autoSubmit();" name="paymentForm" id="paymentForm" action="{{ $actionTo }}">
        <input type="hidden" name="Version" value="{{ $version }}"><br>
        <input type="hidden" name="MerID" value="{{ $merchantId }}"><br>
        <input type="hidden" name="AcqID" value="{{ $acquireId }}"><br>
    </form>
    <script type="text/javascript">

            function autoSubmit() {
                document.forms["paymentForm"].submit();
            }

    </script>
0 likes
5 replies
bugsysha's avatar

Don't mind me asking, but what is the point of that form?

Something like this should work:

document.addEventListener('DOMContentLoaded', () => {
  document.querySelector('form').submit();
});
1 like
ethar's avatar
Level 5

@bugsysha Thanks It must be redirected me to the payment page with form input values,

your way not working

ethar's avatar
Level 5

@bugsysha thanx solved


    <form method="post" name="paymentForm" id="paymentForm" action="{{ $actionTo }}">
        <input type="hidden" name="Version" value="{{ $version }}"><br>
        <input type="hidden" name="MerID" value="{{ $merchantId }}"><br>
    </form>
    <script type="text/javascript">
                document.forms["paymentForm"].submit();
    </script>
CorvS's avatar

Would be nice if you could accept @bugsysha's (or your) answer as the best answer then, so the question is marked as "solved".

1 like
bugsysha's avatar

Thanks for that, but I've got used to the fact that the majority does not come back to mark is as solved. I guess that Jeffrey should create some kind of auto-close bot.

Please or to participate in this conversation.