Trouble with an auto-submitting form

2019-09-03 16:49发布

I'm working on an intermediary form that will gather some data from the user submitted form, and then re-build the form and send it to our authorizer in the appropriate format. Everything is working fine except that I cannot get it to submit this secondary form automatically. I have read several other posts on SO regarding this issue, but they all seem to be requiring a trigger to then submit the form, which mine does not. I simply require it to submit, and my jQuery seems to be taking a nap.

...data gathered here...

echo "<html><head></head><body>";

echo "<form id='forwarderForm' method='post' action='https://www.beanstream.com/scripts/process_transaction.asp'>";

    //rebuild the form to send to beanstream
    $keys = array_keys($_POST);
    for($i = 0; $i < count($_POST); $i++) {
        $currentKey = $keys[$i];
        $currentPost = $_POST[$currentKey];
        echo "<INPUT TYPE='hidden' NAME='" .$currentKey. "' VALUE='" .$currentPost. "'>";
    }
echo "</form>

<script type='text/javascript'>

$('#forwarderForm').submit();

</script></body></html>  ";

I have also tried removing the jQuery from the PHP echo, but this does not work either. when using a standard submit button to send the form, everything works fantastic, but I can't get it to submit by itself.

I added the HTML/HEAD/BODY tags later because I was unsure if they mattered for the purposes of a simple form construct/submit, but this did not appear to change anything.

any comments, suggestions and advice is greatly appreciated. I know it's probably something very simple that's eluding me, so your help is appreciated.

1条回答
ゆ 、 Hurt°
2楼-- · 2019-09-03 17:25

You will need to add this in a document.ready clause, like this

<script>
$(document).ready(function () { $('#forwarderForm').submit(); } );
</script>
查看更多
登录 后发表回答